Property Getter and Setter : Properties : Class C# Examples


C# Examples » Class » Properties »

 

Property Getter and Setter









    
using  System;
      
class  Address
{
        protected  string  city;
        public  string  City
        {  
          get  {  return  city;  }
        }
      
        protected  string  zipCode;
        public  string  ZipCode
        {
                get  {  return  zipCode;  }
                set  
                {  
                        zipCode  =  value;  
                        city  =  "Atlanta";
                }
        }
}
      
class  PropertyApp
{
        public  static  void  Main()
        {
                Address  addr  =  new  Address();
                addr.ZipCode  =  "30338";
                string  zip  =  addr.ZipCode;
      
                Console.WriteLine("The  city  for  ZIP  code  {0}  is  {1}",  addr.ZipCode,  addr.City);
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Properties