使用泛型类型'System.Collections.Generic.List'需要'1' [英] Using the generic type 'System.Collections.Generic.List' requires '1'
本文介绍了使用泛型类型'System.Collections.Generic.List'需要'1'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static List<T> GetDriveTemp()
{
List<T> retval = new List<T>();
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI", "SELECT * FROM MSStorageDriver_ATAPISmartData");
//loop through all the hard disks
foreach (ManagementObject queryObj in searcher.Get())
{
byte[] arrVendorSpecific = (byte[])queryObj.GetPropertyValue("VendorSpecific");
//Find the temperature attribute
int tempIndex = Array.IndexOf(arrVendorSpecific, TEMPERATURE_ATTRIBUTE);
retval.Add(arrVendorSpecific[tempIndex + 5]);
}
}
catch (ManagementException err)
{
Console.WriteLine("An error occurred while querying for WMI data: " + err.Message);
}
return retval;
}
在此代码中我收到此错误 使用泛型类型''System.Collections.Generic.List< t>''需要''1''
推荐答案
你正在尝试将byte
插入到定义为List< string>
的对象中。您还错过了方法定义中返回类型的类型规范。
You are trying to insert abyte
into an object defined as aList<string>
. You have also missed the type specification from the return type on your method definition.
这篇关于使用泛型类型'System.Collections.Generic.List'需要'1'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文