Solved

Loop through IDictionary

Posted on 2009-05-07
2
2,664 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 500 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

Let’s list some of the technologies that enable smooth teleworking. 
If your app took Google’s lash recently, here are the 5 most likely reasons.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

717 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