Property And its associated Field : Properties : Class C# Examples


C# Examples » Class » Properties »

 

Property And its associated Field









    
using  System;


class  MyClass
{
      private  int  privateInnerValue  =  10;  
      public  int  MyValue                                    
      {
            set  {  
                  privateInnerValue  =  value;  
            }
            get  {  
                  return  privateInnerValue;  
            }  
      }
}
class  MainClass
{
      static  void  Main()
      {
            MyClass  c  =  new  MyClass();
            Console.WriteLine("MyValue:  {0}",  c.MyValue);
            c.MyValue  =  20;
            Console.WriteLine("MyValue:  {0}",  c.MyValue);
      }
}
    
   
  
   



Output

MyValue: 10
MyValue: 20


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Properties