如何获得IEnumerable< string>键?在SortedDictionary中 [英] how get IEnumerable<string> key? inside the SortedDictionary
本文介绍了如何获得IEnumerable< string>键?在SortedDictionary中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有
SortedDictionary<string, IEnumerable<string>>
i循环过关于我的IEnumerable项目如何获得密钥?
i loop over the IEnumerable items in foreach how i get the key ??
foreach (IEnumerable<string> item in songs.Values)
{
/// i need to get the key of the "IEnumerable" item
}
推荐答案
试试这个:
SortedDictionary<string, IEnumerable<string>> songs = ...;
foreach(string key in songs.Keys)
{
var value = songs[key];
...
}
干杯
Andi
Cheers
Andi
就我而言,你无法获得密钥知道。您必须迭代 KeyValuePair
,如文档中所示:字典< TKey,TValue> .Values属性 [ ^ ]。
You cannot get the key, as far as I know. You have to iterate over the KeyValuePair
s as shown in the documentation: "Dictionary<TKey, TValue>.Values Property"[^].
这篇关于如何获得IEnumerable< string>键?在SortedDictionary中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文