我有一個包含名爲Values的公用字典的類Locale。
我要的是:更改自定義類方括號返回值
Locale l = new Locale(.....);
// execute stuff that loads the Values dictionary...
// currently to get the values in it I have to write :
string value = l.Values["TheKey"];
// What I want is to be able to get the same thing using :
string value = l["TheKey"];
我想基本上都採用了自定義類方括號時改變返回值。
您可以創建一個'索引屬性'https://msdn.microsoft.com/en-in/library/aa288464(v=vs.71).aspx –
它被稱爲[索引器](https:// msdn。 microsoft.com/en-us/library/6x16t2tx.aspx)在C#中。 – Han
@ Handoko.Chen是的!對。 –