پاسخ تمرین های فصل : تمرین و تثبیت مطالب آموخته شده
زیر فصل: بازنویسی
-
کد زیر را با دستور switch بازنویسی کنید:
int seasonNumber = 2;
if(seasonNumber == 1)
{
Console.WriteLine("Season is Spring");
}
else if(seasonNumber == 2)
{
Console.WriteLine("Season is Summer");
}
else if(seasonNumber == 3)
{
Console.WriteLine("Season is Autumn");
}
else if(seasonNumber == 4)
{
Console.WriteLine("Season is Winter");
}
else
{
Console.WriteLine("Invalid Season");
}int seasonNumber = 2;
switch (seasonNumber)
{
case 1:
Console.WriteLine("Season is Spring");
break;
case 2:
Console.WriteLine("Season is Summer");
break;
case 3:
Console.WriteLine("Season is Autumn");
break;
case 4:
Console.WriteLine("Season is Winter");
break;
default:
Console.WriteLine("Invalid Season");
break;
}