Click here to Skip to main content
15,888,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have
SortedDictionary<string, IEnumerable<string>>

i loop over the IEnumerable items in foreach how i get the key ??

XML
foreach (IEnumerable<string> item in songs.Values)
     {
              /// i need to get the key of the "IEnumerable" item 
     }
Posted

Try this:
C#
SortedDictionary<string, IEnumerable<string>> songs = ...;
foreach(string key in songs.Keys)
{
    var value = songs[key];
    ...
}
Cheers
Andi
 
Share this answer
 
Comments
Member 10631195 3-Oct-14 19:37pm    
Thank you very much it's funny but it seems like that just broke my head
You cannot get the key, as far as I know. You have to iterate over the KeyValuePairs as shown in the documentation: "Dictionary<TKey, TValue>.Values Property"[^].
 
Share this answer
 
Comments
Member 10631195 3-Oct-14 16:45pm    
I do not exactly understand what i need to change
Member 10631195 3-Oct-14 17:53pm    
http://jpg.co.il/view/542f19ef1aadb.bmp/
[no name] 3-Oct-14 16:57pm    
use foreach( KeyValuePair<string, string=""> kvp in songs)
Member 10631195 3-Oct-14 17:17pm    
i tray this: KeyValuePair<string,ienumerable<string>> kvp=songs.Values;
Cannot implicitly convert type
Dictionary<string,system.collections.generic.ienumerable<string>>.ValueCollection
to
KeyValuePair<string,ienumerable<string>> kvp=songs.Values;
Member 10631195 3-Oct-14 17:41pm    
???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900