Sunday 15 July 2012

properties - c# property setter body without declaring a class-level property variable -


Do I need to declare class-level variable to have a property, or do I just want to self Can I refer? {Propertyname} in the gate / setter?

In other words, can I do this? (Where I have not defined anywhere mongoFormId ):

  public string mongoFormId {get {return this.mongoFormId; } Set {this.mongoFormId = value; RevalidateTransformation (); }}    

You either apply auto accessers or Can your own? If you use automatic accessor, the C # compiler will prepare a backing field for you, but if you follow your own you must manually provide a banking field (or handle the value in some other way) Will happen).

  Private string _mongoFormId; Get public string mongoFormId {this._mongoFormId; } Set {this._mongoFormId = value; RevalidateTransformation (); }}   

Update: Since this question was asked, C # 6.0 has been released. However, even with that, there is still no way to provide a custom setter body, without needing to declare a backing field.

No comments:

Post a Comment