can encapsulate private field through automatic property in c#? when use c# properties surely can encapsulate private fields like.
private string owner; public string owner { { return owner; } set { owner=value;} }
what happens when use automatic property?
public string owner { get; set; }
that way interact property itself, right? there way use automatic property encapsulate private field? how work?
is there way use automatic property encapsulate private field?
yes; exactly automatically implemented property is. simply: compiler declares field - never see field directly. perhaps real question here should be:
if use automatically implemented property, can access underlying field directly?
to answer is: no; access property instead. after jit inlining, you'll never know difference anyway.
Comments
Post a Comment