这个lambda表达式的C#2.0等效代码是什么

这个lambda表达式的C#2.0等效代码是什么,lambda,c#-3.0,c#-2.0,Lambda,C# 3.0,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>

我需要一个通过打开的资源管理器窗口枚举的功能。这是我得到的一个代码:

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;
}

我的问题是,在第一段代码中,如何替换lambda表达式,以便在VS 2005中使用C#2.0编译代码。

创建一个新方法以传递到
EnumThreadWindows
,如下所示:

[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);
    }
}
static bool EnumThreadCallback(IntPtr hWnd, IntPtr lParam)
{
    // Close the enumerated window.
    PostMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);

    return true;
}
foreach (ProcessThread pt in proc.Threads)
{
    EnumThreadWindows((uint)pt.Id, new EnumThreadDelegate(EnumThreadCallback), IntPtr.Zero); 
}
并让一名代表随行:

public delegate bool EnumThreadDelegate (IntPtr hWnd, IntPtr lParam);
然后像这样调用函数:

[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);
    }
}
static bool EnumThreadCallback(IntPtr hWnd, IntPtr lParam)
{
    // Close the enumerated window.
    PostMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);

    return true;
}
foreach (ProcessThread pt in proc.Threads)
{
    EnumThreadWindows((uint)pt.Id, new EnumThreadDelegate(EnumThreadCallback), IntPtr.Zero); 
}
来源:

委托bool EnumThreadDelegate(IntPtr hWnd,IntPtr lParam);
静态IEnumerable EnumerateProcessWindowHandles(int-processID)
{
列表句柄=新列表();
EnumThreadDelegate addWindowHandle=委托(IntPtr hWnd,IntPtr param)
{
句柄。添加(hWnd);
返回true;
};
foreach(Process.GetProcessById(processID.Threads)中的ProcessThread线程)
{
EnumThreadWindows(thread.Id、addWindowHandle、IntPtr.Zero);
}
返回手柄;
}

这似乎正是我想要的!我很快就回来