在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)
我想在我自己的类型中实现它们更清洁。
这是什么意思?为什么你不能只使用普通的常规方法获取和设置? – Timwi 2011-01-18 23:53:43
只是觉得有人可能会想出更好的解决方案。用这种方式看起来并不高雅,但仅仅是实验。 – 2011-01-19 00:17:34