Solved

Loop through IDictionary

Posted on 2009-05-07
2
2,644 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
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
Guess #1:

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

Accepted Solution

by:
drmason earned 500 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A list of useful business intelligence software.
Let’s list some of the technologies that enable smooth teleworking. 
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now