用linq查询windows服务出错,谁帮帮我吧!
ServiceController[] MyServices = ServiceController.GetServices();
var scoreQuery =
from srv
in MyServices
select srv;
foreach (int i in scoreQuery)
{ listViewServices.Items.Add(MyServices[i].DisplayName); }
出现Error Cannot convert type 'System.ServiceProcess.ServiceController' to 'int'
可能是因为这里的MyServices 不是int型的,但是MyServices[i].DisplayName里面的i必须要是int型才能添加,怎么改啊?谢谢了!
------解决方案--------------------什么叫LINQ,问什么要用LINQ?
你需要的是这样的内容?
var scoreQuery =
from svc
in ServiceController.GetServices()
select svc;
foreach (var svc scoreQuery)
{ listViewServices.Items.Add(svc.DisplayName); }