我需要一個通過打開的資源管理器窗口枚舉的功能。這裏是我有一個代碼:什麼是此lambda表達式的C#2.0等效代碼
delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumThreadWindows(int dwThreadId, EnumThreadDelegate lpfn, IntPtr lParam);
static IEnumerable<IntPtr> EnumerateProcessWindowHandles(int processID)
{
List<IntPtr> handles = new List<IntPtr>();
foreach (ProcessThread thread in Process.GetProcessById(processID).Threads)
{ //what is the magic going on beneath this?? :o
EnumThreadWindows(thread.Id, (hWnd, lParam) => { handles.Add(hWnd); return true;}, IntPtr.Zero);
}
return handles;
}
和代碼繼續在這裏是這樣的:
[DllImport("coredll.dll")]
static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_MINIMIZED = 6;
private void button1_Click(object sender, EventArgs e)
{
foreach (IntPtr handle in EnumerateProcessWindowHandles(Process.GetProcessesByName("explorer")[0].Id))
{
ShowWindow(handle, SW_MINIMIZED);
}
}
我的問題是,在第一個代碼塊,我怎麼更換lambda表達式這樣我可以在VS使用C#2.0編譯代碼2005
這似乎正是我」正在尋找!我會盡快回復 – nawfal 2012-02-23 14:55:05