Use readonly : readonly « Class « C# / CSharp Tutorial






You can create a read-only field in a class by declaring it as readonly.

A readonly field can be initialized, but not changed after that.

using System; 
 
class MainClass { 
  public static readonly int SIZE = 10; 
  
  public static void Main() { 
    int[] nums = new int[MainClass.SIZE]; 
 
    // MainClass.SIZE = 100; // Error!!! can't change 
  } 
}








7.36.readonly
7.36.1.Use readonly
7.36.2.Readonly Fields
7.36.3.static readonly fields
7.36.4.Readonly and const
7.36.5.Creating a read-only property.