在下面的示例中,this[] 在类中用于从类即时的某处获取值。这个值存储在哪里?可能是 [] 运算符被重载了,还是这只是我不熟悉的 c# 语法?
public class MyUserSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[DefaultSettingValue("white")]
public Color BackgroundColor
{
get
{
return ((Color)this["BackgroundColor"]);
}
set
{
this["BackgroundColor"] = (Color)value;
}
}
}
最佳答案
那叫做indexer .它与类的重载运算符非常相似。在该类的其他地方,或在其中一个类的基类中,定义了一个索引器。
关于c# - 使用 this[] 关键字从类实例中检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13310077/