foreach is mainly just for arrays. right? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

foreach is mainly just for arrays. right?

7th Aug 2016, 3:39 PM
Fawad Ghori
Fawad Ghori - avatar
3 Answers
+ 2
nope absolutely not! There are often classes with the IEnumerable interface for example the List<T> where you use either LINQ or foreach for a good readable code
8th Aug 2016, 11:46 AM
Gabriel “zogglerplays” Schwienbacher
Gabriel “zogglerplays” Schwienbacher - avatar
0
no foreach used for eny thing consist more than one and you want to make an operation on all them in one step so that use foreach
9th Aug 2016, 2:18 PM
Maichael Nasr
Maichael Nasr - avatar
0
no, foreach is used whenever you need to go thru all items, like values, words, rows in files etc.
20th Nov 2016, 6:22 PM
Nenad Puhalo
Nenad Puhalo - avatar