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

WBOY
Release: 2023-09-04 21:13:14
forward
1022 people have browsed it

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"
};
Copy after login

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;
      }
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!