C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C#

Can I use foreach instead of for when looping?

22nd Feb 2017, 2:36 PM
Trinity Duffy
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); }
22nd Feb 2017, 3:44 PM
Marco Bimbati
Marco Bimbati - avatar
0
Yes, arrays has enumerator
22nd Feb 2017, 2:56 PM
Nick Kuleba
Nick Kuleba - avatar