Solved

Loop through IDictionary

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wireless name in LAN adapter 14 81
Pay to 支付宝 12 69
WINZIP - command line function to output directory of all zipped files 17 49
SSRS Deployment problem 5 97
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.

726 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