CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

foreach Sum Over an Array

C# code walkthrough · Question 16
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