相关疑难解决方法(0)

定义类的属性

谁能告诉我两者之间的区别

public class Vendor
{
    public string VendorName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

public class Vendor
{
    private string vendorName = string.Empty; 

    public string VendorName
    {
        get { return vendorName; }
        set { vendorName = value; }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用私有变量有什么好处吗?这样做只会浪费时间和线条吗?在课堂上没有对该属性进行任何操作.

谢谢

c# properties

1
推荐指数
1
解决办法
403
查看次数

标签 统计

c# ×1

properties ×1