c# - Simple Syntax for Declaring properties with a starting value -
well far, shortest code i've seen declare property can set inside class i've seen is:
public t property {get; private set;}
but if want declare starting value (which not default value type), how it??
actually i'm doing this:
public t property {get; private set;} private void initialize() {property = value; }
another option is:
private t _property = value; public property {get {return _property;}}
but i'm wondering if can write 1 code line only, because i'll writing many of properties, , don't want have duplicate line each.
nope. auto-properties always default default value.
your best bet set them in constructor, or else not use auto-property.
public t property {get; private set;} public myclass() { property = value; }
Comments
Post a Comment