User FAQs

If you have a question, please send it to us.


1) Write a For loop to display the values in a list ?

System.Collections.Generic.List<int>MyList; 
for (int mynumber = 0; mynumber < MyList.Length; mynumber++)
{
    MessageBox.Show(MyList[mynumber]);
}

2) Write a For-Each loop to display the values in a list ?

System.Collections.Generic.List<int>MyList; 
foreach (int mynumber in MyList)
{
    MessageBox.Show(mynumber);
}

3) Describe the 'return' statement and explain where it can be used ?
return - terminates execution of the method in which it appears and returns control to the calling method.


4) What is the difference between 'break' and 'continue' inside a for loop ?
break - breaks out of the loop completely.
continue - continues to execute the next iteration.

for (int i = 0; i < 10; i++) 
{
    if (i == 0)
    {
        continue; // the for-loop will jump to the next loop
    }
    DoSomeThing(i);
    if (i == 5)
    {
        break; // the for-loop with exit
    }
}

5) Write a Switch statement to match against two conditions ?

switch (myNumber) 
{
   case < 10:
      break;
   case >= 10:
      break;
   default:
      break;
}


© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext