標準字典是這樣的:C#如何循環使用多個字典?
public Dictionary<int, DictionarySetup> H = new Dictionary<int, DictionarySetup>()
{
{18000, new DictionarySetup { Some values }},
};
從AT一應俱全,所有這些都是在一個叫DictionaryInit類,現在我檢查值,如果有一個符合這種布爾:
public Boolean Dictionary_Test(Dictionary<int, DictionarySetup> AccountLexicon)
{
DictionarySetup ClassValues;
if (AccountLexicon.TryGetValue(MapKey, out ClassValues))
{
return true;
}
return false;
}
現在,我正在尋找通過每個字典更有效的方法來循環,如果有一個匹配,獲取特定字典用於後續的方法的使用,這是它看起來像現在在if/else語句:
if(Dictionary_Test(theDictionary.C) == true)
{
Dictionary_Find(Account_String, rowindex, theBSDictionary.C, Cash_Value, txtCurrency.Text);
}
else if (Dictionary_Test(theDictionary.D) == true)
{
Dictionary_Find(Account_String, rowindex, theDictionary.D, Cash_Value, txtCurrency.Text); //Method that makes use of the dictionary values, above dictionary checks only if it exists
}
用A-T的字典,這將是很多if/else的!有一個更好的方法嗎?我發現一個線程提到這個相同的話題,通過添加字典到字典數組[]然後循環,但如何找到匹配字典的名稱,或使我的第二個方法Dictionary_Find,使用匹配的字典?
爲什麼不只是有一個字典的列表,而不是有dictionary_A-T? – Rob