Using command-line arguments to initialize an array. - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

Using command-line arguments to initialize an array.

Demo Code



using System;/*from w  w  w.  ja  v  a  2  s  .  c o m*/

class MainClass
{
   static void Main(string[] args)
   {
         var arrayLength = 5;
         var array = new int[arrayLength]; // create array

         var initialValue = 2;
         var increment = 3;

         for (var counter = 0; counter < array.Length; ++counter)
         {
            array[counter] = initialValue + increment * counter;
         }

         Console.WriteLine($"{"Index"}{"Value",8}");

         // display array index and value
         for (int counter = 0; counter < array.Length; ++counter)
         {
            Console.WriteLine($"{counter,5}{array[counter],8}");
         }

   }
}

Result


Related Tutorials