For Loop:-
int[] myname = new int[1];
int count = 0;
for (int i = 0; i < myname.Length; i++)
{
count += myname[i];
}
Foreach Loop:-
string[] days = { "sunday", "Monday", "Wednesday", "Thursday", "Friday", "Saturday", "sunday" };
foreach (string day in days)
{
Label1.Text = day.ToString();
}
The above C# example first declared a string array 'days' and initialize the days in a week to that array. In the foreach loop declare a string 'day' and pull out the values from the array one by one and displayed it.
How to switch case statement:
int val=5;
switch (val)
{
case 1:
Label1.Text = "Sunday";
break;
case 2:
Label1.Text = "Monday";
break;
case 3:
Label1.Text = "Tuesday";
break;
case 4:
Label1.Text = "Wednesday";
break;
case 5:
Label1.Text = "Thrusday";
break;
case 6:
Label1.Text = "Friday";
break;
case 7:
Label1.Text = "Saturday";
break;
}
No comments:
Post a Comment