What are static or fixed length arrays in C#?

CsharpProgrammingServer Side Programming

A static array is a data structure with a fixed size. Let us see an example of a static array in C#.

Here is a static string array. The data remains the same here i.e. fixed −

static string[] _fruits = new string[] {
   "apple",
   "mango"
};

Now let us see the complete example to create and access static arrays in C# −

Example

using System;

class Demo {
   static void Main() {
      foreach (string fruits in Program.Fruits) {
         Console.WriteLine(fruits);
      }
   }
}

public static class Program {

   static string[] _fruits = new string[] {
      "apple",
      "mango"
   };

   public static string[] Fruits {
      get {
         return _fruits;
      }
   }
}
raja
Published on 13-Aug-2018 08:54:37
Advertisements