C#使用System.Environment获取电脑的相关属性
作者:在代码的世界里游走 时间:2023-11-08 21:26:39
使用System.Environment获取电脑的相关属性,入门案例,具体内容如下
static void Main(string[] args)
{
MyComputer myNotebook = new MyComputer();
myNotebook.ComputerInfo();
Console.ReadKey();
}
public class MyComputer
{
private string Domain;
private string No;
private string User;
private string[] Drives;
private string OS;
private Version Version;
private int ProcessorCount;
public string Name
{
get
{
return this.No;
}
}
public MyComputer()
{
this.User = System.Environment.UserName;
this.No = System.Environment.MachineName;
this.Domain = System.Environment.UserDomainName;
this.Drives = System.Environment.GetLogicalDrives();
this.OS = System.Environment.OSVersion.ToString();
this.Version = System.Environment.Version;
this.ProcessorCount = System.Environment.ProcessorCount;
}
public void ComputerInfo()
{
Console.WriteLine("当前电脑所在的域名:{0}", Domain);
Console.WriteLine("当前电脑的用户是:{0}", User);
Console.WriteLine("当前电脑的名字是:{0}", No);
Console.WriteLine("当前电脑的操作系统版本:{0}", OS);
Console.WriteLine("当前电脑的系统版本:{0}", Version);
Console.WriteLine("当前电脑的处理器个数:{0}", ProcessorCount);
Console.WriteLine("当前电脑的驱动器有:");
foreach (var item in Drives)
{
Console.WriteLine("{0}驱动器下的目录有:", item);
Console.WriteLine("=========================================================");
string[] d = Directory.GetDirectories(item);
foreach (var d1 in d)
{
Console.WriteLine(d1);
}
}
}
}
来源:https://www.cnblogs.com/ChengWenHao/p/GetComputerInfo.html
标签:C#,System.Environment,电脑属性
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android使用ScrollView实现滚动效果
2023-05-01 13:25:16
c#源码的执行过程详解
2023-10-01 17:03:37
![](https://img.aspxhome.com/file/2023/5/113725_0s.png)
idea中如何去掉不想commit的文件
2021-11-09 15:51:30
![](https://img.aspxhome.com/file/2023/0/113480_0s.png)
详解jeefast和Mybatis实现二级联动的问题
2022-11-10 05:10:15
![](https://img.aspxhome.com/file/2023/3/116823_0s.png)
c#代码生成URL地址的示例
2022-02-17 09:44:08
opencv配置的完整步骤(win10+VS2015+OpenCV3.1.0)
2023-06-28 14:55:19
![](https://img.aspxhome.com/file/2023/4/100304_0s.png)
android studio 使用Mocklocation虚拟定位
2022-12-31 12:26:34
![](https://img.aspxhome.com/file/2023/7/120147_0s.png)
解决Android webview设置cookie和cookie丢失的问题
2021-09-12 21:55:52
Java反射(Class类,Class对象获取)
2021-06-27 05:55:24
![](https://img.aspxhome.com/file/2023/4/63444_0s.png)
为什么Spring和IDEA都不推荐使用 @Autowired 注解
2023-12-08 17:54:44
![](https://img.aspxhome.com/file/2023/9/66029_0s.png)
XFire构建web service客户端的五种方式
2021-08-30 21:56:16
java 实现截取字符串并按字节分别输出实例代码
2021-08-28 08:10:44
Spring Boot使用profile如何配置不同环境的配置文件
2023-11-25 12:52:36
![](https://img.aspxhome.com/file/2023/2/59932_0s.png)
C#难点逐个击破(4):main函数
2021-06-18 17:47:43
![](https://img.aspxhome.com/file/2023/1/119511_0s.png)
Android自定义可循环的滚动选择器CycleWheelView
2023-04-06 00:43:16
![](https://img.aspxhome.com/file/2023/8/138718_0s.png)
60条Android开发注意事项与经验总结
2021-12-07 11:55:16
java 中如何实现 List 集合去重
2023-10-07 07:54:06
![](https://img.aspxhome.com/file/2023/9/58549_0s.webp)
JavaSwing BorderLayout 边界布局的实现代码
2023-04-23 08:03:40
![](https://img.aspxhome.com/file/2023/2/75002_0s.png)
Kotlin 高阶函数与Lambda表达式示例详解
2021-06-18 08:58:15
![](https://img.aspxhome.com/file/2023/2/138792_0s.png)
Android中实现Webview顶部带进度条的方法
2022-04-22 15:45:43
![](https://img.aspxhome.com/file/2023/2/116142_0s.png)