gpt4 book ai didi

C# 构造函数使用私有(private)/公共(public)字段

转载 作者:行者123 更新时间:2023-11-30 13:22:53 25 4
gpt4 key购买 nike

<分区>

class Student
{
private string firstName;

public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value; // Possible logical checks may be implemented here in the future
}
}

public Student (firstName)
{

this.firstName = firstName; // Option 1
// Or
FirstName = firstName; // Option 2

}
}

这两条线哪一条更标准?

我们在构造函数中使用私有(private)成员还是公共(public)成员?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com