Shorthand Accessors and Mutators

梦想的初衷 提交于 2019-11-30 08:40:26

Yes, Method 1 is a shortcut to Method 2. I suggest using Method 1 by default. When you need more functionality, use Method 2. You can also specify different access modifiers for get and set.

Yes, the Method2 is the way to go when you have a custom getter and setter function. By default when you use Method1, there will be a default private property handled internally. Please refer this URL for more details.

Sample:

string _name;

public string Name 
{
    get => _name;
    set => _name = value;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!