当前位置: 移动技术网 > IT编程>开发语言>c# > C#使用System.Environment获取电脑的相关属性

C#使用System.Environment获取电脑的相关属性

2019年07月18日  | 移动技术网IT编程  | 我要评论
使用system.environment获取电脑的相关属性,入门案例,具体内容如下 static void main(string[] args) {

使用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);
     }
    }
   }
  }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网