gpt4 book ai didi

c# - 使用 System.Reflection 打印所有 System.Environment 信息

转载 作者:太空狗 更新时间:2023-10-29 22:13:48 26 4
gpt4 key购买 nike

我们有一个小任务是使用反射在控制台窗口中打印Environment类的所有变量,但是我什至不知道如何做线索。如果我在这里写错了,我很抱歉,我是 C# 的新手。

我当然可以使用这种代码,但这不是我所需要的。

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

我在 Google 上搜索了很多次,这就是我找到的,但我认为这不是我需要的。我什至不知道我需要什么。

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

有什么建议、线索吗?

最佳答案

这里不需要反射(reflection)

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

var compName = System.Environment.GetEnvironmentVariables()["COMPUTERNAME"];

关于c# - 使用 System.Reflection 打印所有 System.Environment 信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23187288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com