【发布时间】:2011-06-11 10:37:07
【问题描述】:
在 C# 中有可能有这样的东西吗?我不太确定:
class Library
{
public string Books[string title]
{
get{return this.GetBookByName(string title);}
}
public DateTime PublishingDates[string title]
{
get{return this.GetBookByName(string title).PublishingDate;}
}
}
所以它可以这样使用:
myLibrary.Books["V For Vendetta"]
myLibrary.PublishingDates["V For Vendetta"] = ...
所以我需要在我的框架中实现(通过调用它们)的完整成员方法是:
GetCustomStringValue (key)
GetCustomIntValue (key)
GetCustomBoolValue (key)
GetCustomFloatValue (key)
SetCustomStringValue (key)
SetCustomIntValue (key)
SetCustomBoolValue (key)
SetCustomFloatValue (key)
我想以我自己的类型更简洁地实现它们。
【问题讨论】:
-
这是什么意思?为什么不能只使用普通的旧常规方法来获取和设置?
-
只是觉得有人可能会想出一个更好的解决方案。以这种方式拥有它似乎并不优雅,而只是实验。
-
多个索引属性可用于 WPF 绑定