还有5,
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
ManagementClass systemEnclosures = new ManagementClass("Win32_SystemEnclosure");
foreach (ManagementObject obj in systemEnclosures.GetInstances())
{
foreach (int i in (Int16[])(obj["ChassisTypes"]))
{
switch (i)
{
case 3:
Console.WriteLine("这是台式机!");
break;
case 8:
case 9:
Console.WriteLine("这是笔记本!");
break;
}
}
}
Console.ReadLine();
1 i 的值为10时是笔记本电脑。
2 bzhkl大牛的程序修改如下:
switch (i)
{
case 3:
Console.WriteLine("这是台式机!");
break;
case 8:
case 9:
case 10:
Console.WriteLine("这是笔记本!");
break;
}