由於代碼的最後一個..看看字典項在字典中
var dictionary = new Dictionary<string, string>{
{ "something", "something-else" },
{ "another", "another-something-else" }
};
dictionary.ForEach(item => {
bool isLast = // ... ?
// do something if this is the last item
});
我基本上是想看看我用一個foreach迭代的容器內工作的項目是在字典中的最後一個項目。我試圖
bool isLast = dictionary[ item.Key ].Equals(dictionary.Last()) ? true : false;
,但沒有奏效...
您是否嘗試過使用計數器並通過foreach比較迭代到字典的大小?字典在理論上是無序的,所以我不會相信與字典的Last值的任何比較。 – 2011-06-02 14:55:49
字典中的「last」究竟是什麼? – user7116 2011-06-02 16:39:36