Categories
Csharp

how to use foreach loop in c sharp application

How to use foreach loop

today i will teach you how to use for each loop in c sharp application before you use for each  …For each loop  use for execute multiple statement  in one time…Syntax of for each loop ..foreach(data type var-name in expression ){
  block of statements}Example Suppose you crate a array which name is a and it range is 4 .you  want to print all the value in array you don’t want to write  multiple  statement to print value of array. so you have better option to print all value of array you use foreach loop


Ans..int[]a=new int[4]{10,20,30,40};

foreach(int x in a)

{

Console.WriteLine(x);

}

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *