-
December 7th, 2014, 07:05 AM
#1
iterating through lists within a dictionary
Hi
c# newbie here just to set the expectations!
Ive set up a dicitionary of Lists and Im trying tho loop through but cannot seem to get the Dicitonary Key :-(
//set up e dicitonary
Dictionary<string, List<string>> hdrAttrAtDict = new Dictionary<string, List<string>>();
//found this to iterte through the contents of the list within the dictionary but not sure how to access the dictionary key itself?
foreach (List<string> list in hdrAttrAtDict.Values)
{
//list.
foreach (string entry in list)
{
//iterating the list of strings for the current dictionary entry.
logger.Debug("hdrAttrAtDict Dictionary: Key[" + "]/--> Value[" + entry + "]...");
}
}
Any help appreiate.. or perhaps there is a better way?
Kind regards
Satnam
-
December 7th, 2014, 07:14 AM
#2
Re: iterating through lists within a dictionary
ha..
having thought about it I may have resolved it with the below:
foreach (KeyValuePair<string, List<string>> entry in hdrAttrAtDict)
{
logger.Debug("Dictionary hdrProdTypeColCountsDict-Key[" + entry.Key + "]--> Value[" + "]..");
foreach (string listEntry in entry.Value)
{
logger.Debug("Dictionary hdrProdTypeColCountsDict-Key[" + entry.Key + "]--> Value[" + listEntry + "]..");
}
}
Would be interested to know if thre was a more concise way of doing it though?
cheers
S
-
December 7th, 2014, 08:24 AM
#3
Re: iterating through lists within a dictionary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|