Home  >  Article  >  Backend Development  >  What is a static array or fixed length array in C#?

What is a static array or fixed length array in C#?

WBOY
WBOYforward
2023-09-04 21:13:141290browse

C# 中的静态数组或固定长度数组是什么?

Static array is a data structure with a fixed size. Let’s look at an example of a static array in C#.

This is a static string array. The data remains unchanged here i.e. fixed -

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

Now let us see the complete example of creating and accessing static array 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;
      }
   }
}

The above is the detailed content of What is a static array or fixed length array in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete