Home »
MCQs »
C# MCQs
Does C# support foreach loop?
42. Does C# support foreach loop?
- Yes
- No
Answer: A) Yes
Explanation:
Yes, C# supports foreach loop. The foreach loop is used to iterate over the elements of the collection. The collection may be an array or a list.
Example:
using System;
class Program {
static void Main(string[] args) {
// an array
int[] arr = new int[] {10, 20, 30, 40, 50};
foreach(int elements in arr) {
Console.WriteLine(elements);
}
}
}
/*
Output:
10
20
30
40
50
*/