Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


In C#, how do you output the contents of a Dictionary class?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 athono   Members   -  Reputation: 132

Like
0Likes
Like

Posted 22 August 2012 - 06:45 PM

In C#, how do you output the contents of a Dictionary class?

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?

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9662

Like
0Likes
Like

Posted 22 August 2012 - 07:04 PM

Did you look at the Dictionary class example code?

#3 Flimflam   Members   -  Reputation: 657

Like
0Likes
Like

Posted 22 August 2012 - 11:46 PM

[source lang="csharp"]foreach (var entry in myDictionary){ Console.WriteLine("Key: {0}, Value: {1}", entry.Key, entry.Value);}[/source]
Super easy. Definitely worth looking into the link SiCrane posted above as well. I'm using var opposed to directly creating a KeyValuePair, which is the actual class the dictionary uses for iteration.

Edited by Flimflam, 22 August 2012 - 11:47 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS