Alex Rivera | Logout

C# Shorthand Property Question

Asked 2009-03-26T19:58:28.287
32

So here is a bit of syntax that I have never seen before, can someone tell me what this means? Not sure if this is supposed to be some shorthand for an abstract property declaration or something or what.

public Class1 myVar { get; set; }

For what its worth, Class1 is an abstract class.

Edit
Report

1 Answer

8

It is shorthand for a property that does nothing more that storing the value in a field. So it would be equivalent to:

private Class1 _myVar;

public Class1 myVar
{
  get{ return _myVar; }
  set{ _myVar = value;}
}

Its just a simple property that yoy could replace with a more complex evantuation at a later time without changing the interface.

answered 2009-03-26T20:04:17.337

Your Answer