+ 2

Display all even elements. Best Practice.

If I would like to print every second element in an array what is the best practice? An if statement in a foreach or a for loop with i+=2? Does the compiler optimize if i use foreach? Is there a better way maybe?

6th Feb 2018, 2:11 AM
Roland Kopka (KOB)
Roland Kopka (KOB) - avatar
1 Odpowiedź
+ 6
You may use foreach for this purpose. Check out the comparison among those two, https://www.dotnetperls.com/for-foreach
6th Feb 2018, 6:06 AM
Dev
Dev - avatar