Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print all System.Environment information using System.Reflection

We have a little task to print in a console window all the variables of the Environment class using reflection, but how to do so I don't even have a clue. I am sorry if I've written anything wrong here, I'm new to C#.

Of course I could use this kind of code, but that is not what is required from me.

string machineName = System.Environment.MachineName;
Console.WriteLine(machineName);

I searched Google so much and this is what I found, but I don't think this is what I need. I don't even know what I need.

System.Reflection.Assembly info = typeof(System.Int32).Assembly;
System.Console.WriteLine(info);

Any suggestions, clues?

like image 852
Arm91 Avatar asked Apr 20 '14 20:04

Arm91


1 Answers

You don't need reflection here

foreach(DictionaryEntry e in System.Environment.GetEnvironmentVariables())
{
    Console.WriteLine(e.Key  + ":" + e.Value);
}

var compName = System.Environment.GetEnvironmentVariables()["COMPUTERNAME"];
like image 92
L.B Avatar answered Oct 24 '22 07:10

L.B