?
Solved

Loop through IDictionary

Posted on 2009-05-07
2
Medium Priority
?
2,666 Views
Last Modified: 2012-05-06
I would like to list the content of the dictionary in the code in this post, but I can't seem to get it right. Could someone help me?
/// <summary>
        /// Get the machine level information.
        /// </summary>
        /// <returns></returns>
        public static IDictionary GetMachineInfo()
        {
            // Get all the machine info.
            IDictionary machineInfo = new SortedDictionary<string, object>();
            machineInfo["Machine Name"] = Environment.MachineName;
            machineInfo["Domain"] = Environment.UserDomainName;
            machineInfo["User Name"] = Environment.UserName;
            machineInfo["CommandLine"] = Environment.CommandLine;
            machineInfo["ProcessorCount"] = Environment.ProcessorCount;
            machineInfo["OS Version Platform"] = Environment.OSVersion.Platform.ToString();
            machineInfo["OS Version ServicePack"] = Environment.OSVersion.ServicePack;
            machineInfo["OS Version Version"] = Environment.OSVersion.Version.ToString();
            machineInfo["OS Version VersionString"] = Environment.OSVersion.VersionString;
            machineInfo["System Directory"] = Environment.SystemDirectory;
            machineInfo["Memory"] = Environment.WorkingSet.ToString();
            machineInfo["Version"] = Environment.Version.ToString();
            machineInfo["Current Directory"] = Environment.CurrentDirectory;
            return machineInfo;
        }

Open in new window

0
Comment
Question by:Ingve
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24337277
Guess #1:

foreach (string key in machineInfo.Keys)
{
    string value = machineInfo[key];
}
0
 
LVL 3

Accepted Solution

by:
drmason earned 2000 total points
ID: 24340693
For a System.Collections.IDictionary:

foreach(DictionaryEntry de in machineInfo)
{
     DoSomething(de.Key, de.Value);
}

For a System.Collections.Generic.IDictionary<string,object> you would use:

foreach(KeyValuePair<string, object> kvp in machineInfo)
{
     DoSomething(kvp.Key, kvp.Value);
}
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
If you're a modern-day technology professional, you may be wondering if certifications are really necessary. They are. Here's why.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question