I
In3rstella
Guest
Hey everyone,
I was just running through switch statement exercises and wrote a method that would take a number from the Main method then run it through a switch statement to see what case it matched and then output a specific day of the week. Unfortunately i'm getting a CS0161 error "not all code paths return a value". I searched around for a bit but didn't find any answers that pointed to why my code might be having the issue. If someone can maybe point out my error to help me understand why it's happening that would be greatly appreciated!
Code:
static void Main(string[] args)
{
int usrNum = 0;
DaysOfWeek(usrNum);
}
static string DaysOfWeek(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;
return dayName;
}
}
Continue reading...
I was just running through switch statement exercises and wrote a method that would take a number from the Main method then run it through a switch statement to see what case it matched and then output a specific day of the week. Unfortunately i'm getting a CS0161 error "not all code paths return a value". I searched around for a bit but didn't find any answers that pointed to why my code might be having the issue. If someone can maybe point out my error to help me understand why it's happening that would be greatly appreciated!
Code:
static void Main(string[] args)
{
int usrNum = 0;
DaysOfWeek(usrNum);
}
static string DaysOfWeek(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;
return dayName;
}
}
Continue reading...