What is the use of 'foreach' statement in C# programming language?

 Posted by Goud.Kv on 9/1/2014 | Category: C# Interview questions | Views: 1277 | Points: 40

foreach is an important statement used in C# and .NET frameworks. It is similar with for statement but it cannot be used to add or remove source items.

foreach (char t in "Dotnetfunda")

Console.WriteLine(t); // This will prints all the 't's present in that string

We can also use break and continue keywords to control the execution like play and pause.
foreach can also be excited by some other jump statements such as throw, return etc.

Asked In: Spotted While Learning | Alert Moderator 

Comments or Responses

Login to post response