我对释放 IDisposable 对象有疑问。
using (ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_Service"))
{
using (ManagementObject item = s.Get().Cast<ManagementObject>().Last())
{
}
}
我是否也应该将 s.Get() 中的集合投入使用?
using (ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_Service"))
{
using (ManagementObjectCollection items = s.Get())
{
using (ManagementObject item = items.Cast<ManagementObject>().Last())
{
}
}
}
linq 是否从我在本主题的第一个代码块中处理集合 (s.Get())?
s.Get().Cast<ManagementObject>().Last()