我有一個代碼,讓寫在vb.net硬盤IDVB代碼轉換爲C#編譯錯誤
現在,我需要重新編寫代碼到C#。我已經將vb.net代碼轉換爲c#,但它沒有編譯。
下面是vb.net代碼
Dim hdCollection As ArrayList = New ArrayList()
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")
For Each wmi_HD As ManagementObject In searcher.Get()
Dim hd As HardDrive = New HardDrive()
hd.Model = wmi_HD("Model").ToString()
hd.Type = wmi_HD("InterfaceType").ToString()
hdCollection.Add(hd)
Next wmi_HD
這裏是轉換後的C#代碼:
ArrayList hdCollection = new ArrayList();
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject wmi_HD in searcher.Get())
{
HardDrive hd = new HardDrive();
hd.Model = wmi_HD("Model").ToString();
hd.Type = wmi_HD("InterfaceType").ToString();
hdCollection.Add(hd);
}
以下是編譯的C#代碼時,我得到的錯誤:
「 wmi_HD」是‘變量’,但使用像一個‘方法’
請幫幫忙!
感謝。這是我的一個愚蠢的錯誤:]並且我已經將ArrayList更改爲列表。謝謝! –
2010-10-12 10:25:53