c# - 在 C# 中是否可以使用同名的公共(public) getter 和私有(private) setter?

标签 c# properties

如何为属性创建公共(public) getter 和私有(private) setter?以下是正确的吗?

public String Password
{
    set { this._password = value; }
}

private String Password
{
    get { return this._password; }
}

最佳答案

是的,即使使用自动属性也是可能的。我经常使用:

public int MyProperty { get; private set; }

关于c# - 在 C# 中是否可以使用同名的公共(public) getter 和私有(private) setter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6082551/

相关文章:

c# - 使用 C# 确定正在设置数组属性的哪个索引

python - 如何检查一个变量是否是一个属性

c# - 查看变量时 Visual Studio 调试器崩溃

c# - 在哪里以及如何获得 Simple Injector 容器?

c# - Json.NET:使用双引号反序列化

properties - 带有下划线的 Vue 属性无效

c# - Windows Phone 8 映射 XAMLParseException

c# - 无法将类型 'System.Linq.IQueryable<int>' 转换为 'int'

java - SimpleProperties 用法

带参数的 Java 属性