C# > Arrays

Single dimensional arrays in C#

How to use single dimensional arrays?


Single dimensional arrays are used to declare single values.

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  class Program
         {
             static void Main()
                  {
                     char[] vowels = new char[5];
                     vowels[0] = 'A';
                     vowels[1] = 'E';
                     vowels[2] = 'I';
                     vowels[3] = 'O';
                     vowels[4] = 'U';
                     Console.WriteLine(vowels[4]);// prints U as the output.
                  }
          }

In the above code snippet we are displaying  5 vowels as characters A, E, I, O, U. In this we are calling vowel number [4] which calls 'U' as the output and prints the value as 'U'.

output:

 Views: 4532 | Post Order: 10



Write for us






Hosting Recommendations