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

Summing an Array With foreach

C# code walkthrough · Question 40
easyArrays

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