3.4C#成员之属性(Property)

属性是字段的自然扩展。

public class Person
{
    public string FirstName { get; set; }

    // remaining implementation removed from listing
}
public class Person
{
    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }
    private string firstName;
    // remaining implementation removed from listing
}

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/csharp/csbasic/8256.html

发表评论

登录后才能评论