根据我在其他地方阅读的内容,似乎一般建议使用字典来动态访问变量/对象和其他字典... 但是我似乎忽略了最后一种情况的简单方法,因为我不知道如何使其工作。基本上,我有多个数据字典,我希望使用变量中的值指向适当的字典并读取其数据:
//----------------------------------------------------------------------------------------
// reference dictionary - pass LangID string to reference appropriate dictionary
public static Dictionary<string, dynamic> myDictionaries = new Dictionary<string, dynamic>()
{
{ "EN", "EN_Dictionary" },
{ "FR", "FR_Dictionary" },
{ "DE", "DE_Dictionary" }
};
//----------------------------------------------------------------------------------------
public static Dictionary<string, string> EN_Dictionary = new Dictionary<string, string>()
// EN language dictionary
{
{ "str1", "Some text in EN" },
{ "str2", "Some text in EN" },
{ "str3", "Some text in EN" }
};
//----------------------------------------------------------------------------------------
public static Dictionary<string, string> FR_Dictionary = new Dictionary<string, string>()
// FR language dictionary
{
{ "str1", "Some text in FR" },
{ "str2", "Some text in FR" },
{ "str3", "Some text in FR" }
};
//----------------------------------------------------------------------------------------
public static Dictionary<string, string> DE_Dictionary = new Dictionary<string, string>()
// DE language dictionary
{
{ "str1", "Some text in DE" },
{ "str2", "Some text in DE" },
{ "str3", "Some text in DE" }
};
//----------------------------------------------------------------------------------------
LangID = "DE";
//... 但现在我该怎么办???
DEstr1
和FRstr1
等 - 键是两个字符串的连接 - 语言代码和实际键。 - Wiktor Zychla