2011-09-25 73 views
0

我有一本词典< int,int >在我的课堂上。如何在不知道密钥的情况下访问这两个值?从词典获取值

举例来说,我希望能够做一些事情是这样的:如果字典包含字典< INT,INT >
和值是< 5,4 >
我希望能够拿到价值的<(本),(这)>像

伪代码:

foreach(Dictionary item or row) 
{ 
    my first int = Dictionary<(this), (not this)> 
    my second int = Dictionary<(not this), (this)> 
} 

我怎样才能做到这一点使用一本字典?如果这不可行:还有其他办法吗?

+0

听起来像'Dictionary'不是您的用例的正确抽象。 –

+0

我需要一个很好的建议:) – user710502

+0

你能详细说明吗?我读了5次,仍然不知道你想要什么...... –

回答

2
foreach (KeyValuePair<int, int> kvp in myDictionary) 
{ 
    var first = kvp.Key; 
    var second = kvp.Value; 
} 
+0

非常感谢,这是我需要的 – user710502

0

em,是不是this同样的问题?

foreach(KeyValuePair<String,String> entry in MyDic) 
{ 
    // do something with entry.Value or entry.Key 
}