gpt4 book ai didi

c# - 访问类的私有(private)成员

转载 作者:行者123 更新时间:2023-11-30 13:31:46 28 4
gpt4 key购买 nike

<分区>

public class Class1
{
private object field;

public Class1(Class1 class1)
{
this.field = class1.field;
}

private void Func(Class1 class1)
{
this.field = class1.field;
}
}

此代码编译并工作。但为什么?我一直认为私有(private)成员只能在类范围内访问。 MSDN 也是这样说的:

The private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared

28 4 0
文章推荐: c# - 从 IEnumerable> linq 选择 IEnumerable