Answer: 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.
Example,
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