CSharp examples for Language Basics:Array
Calculating values to be placed into the elements of an array.
using System;// w w w .ja v a 2 s . c o m class MainClass { static void Main() { const int ArrayLength = 5; // create a named constant int[] array = new int[ArrayLength]; // create array for (int counter = 0; counter < array.Length; ++counter) { array[counter] = 2 + 2 * counter; } Console.WriteLine($"{"Index"}{"Value",8}"); // headings for (int counter = 0; counter < array.Length; ++counter){ Console.WriteLine($"{counter,5}{array[counter],8}"); } } }