Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

Static / Fixed Length Arrays ใน C#

Static Array คือโครงสร้างข้อมูลขนาดคงที่ (Fixed Size) ตัวอย่าง Static String Array:

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

ตัวอย่างสมบูรณ์: สร้างและเข้าถึง Static Array

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; }
    }
}