Mega Code Archive

 
Categories / C# / Class Interface
 

Demonstrate readonly

/* C#: The Complete Reference  by Herbert Schildt  Publisher: Osborne/McGraw-Hill (March 8, 2002) ISBN: 0072134852 */ // Demonstrate readonly.    using System;    class MyClass {    public static readonly int SIZE = 10;  }    public class DemoReadOnly {    public static void Main() {      int[]nums = new int[MyClass.SIZE];        for(int i=0; i<MyClass.SIZE; i++)        nums[i] = i;        foreach(int i in nums)        Console.Write(i + " ");        // MyClass.SIZE = 100; // Error!!! can't change    }  }