我想在 label1 中显示有关处理器的信息。
但是出现错误
无法将类型“System.Collections.Generic.List”隐式转换为“字符串”
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Diagnostics;
namespace simple
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static List<string> GetHardwareInfo(string WIN32_Class, string ClassItemField)
{
List<string> result = new List<string>();
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM " + WIN32_Class);
try
{
foreach (ManagementObject obj in searcher.Get())
{
result.Add(obj[ClassItemField].ToString().Trim());
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return result;
}
private void Form1_Load(object sender, EventArgs e)
{
List<string> process = GetHardwareInfo("Win32_Processor", "Name");
label2.Text = process;
}
这是为什么?怎么修?
label2.Text = process[0]从列表中选择一个值是值得的。