Hi everybody,
I am a newbie in C#.
I have a fragment code but it doesn't run.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number;
string type;
number = 5;
if (number % 2 == 1)
type = "odd";
else if (number % 2 == 0)
type = "even";
Console.WriteLine(type);
}
}
}
I received a error message: "Use of unassigned local variable 'type'"
But when I replace this fragment code:
else if (number % 2 == 0)
type = "even";
by
else
type = "even";
my code ran correctly.
Can you explain for me why?
Thanks for your helps.