CSharp examples for Language Basics:Array
Computing the sum of the elements of an array.
using System;//from w w w . java2 s .co m class SumArray { static void Main() { int[] array = {17, 61, 92, 120, 232, 272, 822, 1, 6, 7}; int total = 0; // add each element's value to total for (int counter = 0; counter < array.Length; ++counter) { total += array[counter]; } Console.WriteLine($"Total of array elements: {total}"); } }