C#中如何使用访问修饰符来修饰属性

时间:2022-04-30 13:13:27

public string ID {get; private set;}

上面的属性对实例公开get方法,而在类里面可以使用set方法。

相应的internal, protected, internal  protected都可以用来修饰属性。注意public不可以,因为默认就是public。