.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Offloading the contents of a Dictionary Class

Posted By: Xarzu     Posted Date: August 22, 2012    Points:5   Category :C#
Once you have loaded a Dictionary class with keys and values, how do I cycle through them and output the individual values in a foreach loop?

Responses
Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

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

To loop a Dictionary

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

A complete example
// Example Dictionary again
Dictionary<string, int> d = new Dictionary<string, int>()
{
{"cat", 2},
{"dog", 1},
{"llama", 0},
{"iguana", -1}
};
// Loop over pairs with foreach
foreach (KeyValuePair<string, int> pair in d)
{
Console.WriteLine("{0}, {1}",
pair.Key,
pair.Value);
}
// Use var keyword to enumerate dictionary
foreach (var pair in d)
{
Console.WriteLine("{0}, {1}",
pair.Key,
pair.Value);
}

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

You can get more information from
http://www.dotnetperls.com/dictionary



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend