adspace
Answer Posted / Anas Malik
The 'foreach' loop in C# is used to iterate through each item in a collection. Its syntax is as follows: nn`foreach (type variable in collection) {n // your code heren}n` where 'variable' is the name given to each item in the collection, and 'collection' is the data structure that contains the items, such as an array, List, or Dictionary. For example, to iterate through an array of integers: nn```nint[] numbers = {1, 2, 3, 4};nforeach (int number in numbers) {n Console.WriteLine(number);n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers