3
Reply

Major and importance difference between for and foreach loop ?

antony romar

antony romar

12y
18.5k
1
Reply

    a for loop is a construct that says "perform this operation n. times".a foreach loop is a construct that says "perform this operation against each value/object in this IEnumerable"

    yes

    For Loop static int Method1(int[] array) {int a = 0;for (int i = 0; i < array.Length; i++){a += array[i];}return a; }Foreach loop static int Method2(int[] array) {int a = 0;foreach (int value in array){a += value;}return a; }