L
Lionile
Guest
So my problem is pretty simple and I imagine there is a simple solution but since I'm still pretty new to c# and coming from c there are just some things I don't fully understand yet
I realised that c# doesn't like it when you leave some stuff unassigned and unlike in c you always have to add an extra "else" or "default" at the end of of a statement.
And so I did..but the program still won't run and still says"use of unassigned local variable 'dayName'", so here it is.
class Program
{
static void Main(string[] args)
{
Console.WriteLine(getDay(2));
Console.ReadLine();
}
static string getDay(int dayNum)
{
string dayName;
switch (dayNum)
{
case 0: dayName = "Monday"; break;
case 1: dayName = "Tuesday"; break;
case 2: dayName = "Wednesday"; break;
case 3: dayName = "Thursday"; break;
case 4: dayName = "Friday"; break;
case 5: dayName = "Saturday"; break;
case 6: dayName = "Sunday"; break;
default: dayName = "Invalid"; break;
}
return dayName;
}
}
As I said, pretty simple code, but I have no clue what to do so if someone can help please do.
Continue reading...
I realised that c# doesn't like it when you leave some stuff unassigned and unlike in c you always have to add an extra "else" or "default" at the end of of a statement.
And so I did..but the program still won't run and still says"use of unassigned local variable 'dayName'", so here it is.
class Program
{
static void Main(string[] args)
{
Console.WriteLine(getDay(2));
Console.ReadLine();
}
static string getDay(int dayNum)
{
string dayName;
switch (dayNum)
{
case 0: dayName = "Monday"; break;
case 1: dayName = "Tuesday"; break;
case 2: dayName = "Wednesday"; break;
case 3: dayName = "Thursday"; break;
case 4: dayName = "Friday"; break;
case 5: dayName = "Saturday"; break;
case 6: dayName = "Sunday"; break;
default: dayName = "Invalid"; break;
}
return dayName;
}
}
As I said, pretty simple code, but I have no clue what to do so if someone can help please do.
Continue reading...