New course! Every coder should learn Generative AI!
Try a free lesson0
C#
Can I use foreach instead of for when looping?
2 Answers
+ 3
Yes, you can.
Example from Microsoft documentation (https://msdn.microsoft.com/it-it/library/ttw7t8t6.aspx):
int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 };
foreach (int element in fibarray)
{
System.Console.WriteLine(element);
}
0
Yes, arrays has enumerator