using System;
public class ReadOnlyClass
{
private readonly int IntegerConstant;
public ReadOnlyClass ()
{
IntegerConstant = 5;
}
// We get a compile time error if we try to set the value of the readonly
//class variable outside of the constructor
public int IntMember
{
set
{
IntegerConstant = value;
}
get
{
return IntegerConstant;
}
}
public static void Main(string[] args)
{
ReadOnlyClass obj= new ReadOnlyClass();
// We cannot perform this operation on a readonly field
obj.IntMember = 100;
Console.WriteLine("Value of IntegerConstant field is {0}",
obj.IntMember);
}
}