Accessors are properties??  
Author Message
IS dude





PostPosted: Visual C# General, Accessors are properties?? Top

Okay so Accessors are properties in C#. In other languages however, (eg Java and C++), Accessors are actually "methods", am I correct



Visual C#12  
 
 
PJ. van de Sande





PostPosted: Visual C# General, Accessors are properties?? Top

Yes, you can see them as methods. For this property:


public String Name
{
 get
 {
  return _name;
 }
 set
 {
  if( _name != value )
  {
   _name = value;
   MarkDirty();
  }
 }
}

 

Two method will be created, get_Name and set_Name. Where get_Name returns a String result and set_Name accepts one string argument.
The simple property accessors are inlined by the JIT-compiler, which means that accessing a field and a property are the same.