CJCoding With Joseph
← Back to Question List
C# Code Walkthrough #16

foreach Sum Over an Array

mediumLoops

📄 Code

Read carefully — what does this print?
1int[] nums = { 4, 8, 15, 16, 23, 42 };
2int total = 0;
3foreach (int n in nums)
4{
5 total += n;
6}
7Console.WriteLine(total);

🎯 Your Answer