Creating a read-only property. : Readonly : Class C# Examples


C# Examples » Class » Readonly »

 

Creating a read-only property.









    
using  System;

public  class  ClassWithReadOnlyProperty  {
        int  fAge;

        public  int  Age  {
                get  {
                        return  fAge;
                }
        }
        public  ClassWithReadOnlyProperty()  {
                fAge  =  21;
        }
}

class  MainClass  {
        static  public  void  Main()  {
                ClassWithReadOnlyProperty  crp  =  new  ClassWithReadOnlyProperty();
                Console.WriteLine("Age  {0}",  crp.Age);

        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Readonly