這裏的一個是我的代碼:如何搜索三重元素(key_value對字典)他們
public class PairedKeys
{
public byte Key_1 { get; set; }
public byte Key_2 { get; set; }
public PairedKeys(byte key_1, byte key_2)
{
Key_1 = key_1;
Key_2 = key_2;
}
}
public static class My_Class
{
static Dictionary<PairedKeys, char> CharactersMapper = new Dictionary<PairedKeys, char>()
{
{ new PairedKeys(128, 48), 'a' },
{ new PairedKeys(129, 49), 'b' }
}
}
我怎樣才能獲得通過搜索Key_2
的CharactersMapper
價值?
這裏是我的嘗試:
for (int j = 0; j < CharactersMapper.Count; j++)
{
try
{
char ch = CharactersMapper[new PairedKeys(????, Key_2)];
}
catch
{
}
}
可能要清理你的代碼了,因此編譯。您的'PairedKeys' ctor缺少圓括號,字典缺少分號。 – 2014-12-03 17:33:16