Question Help translate code from C#2.0 to vb.net 2.0

magozeta

New member
Joined
Jun 4, 2012
Messages
2
Programming Experience
1-3
Hello!
Can you help me to translate from c#2.0 to vb.net 2.0

I use vs2008

I've already tried with some conversion tool site but doesn't work

delegate bool EnumThreadDelegate(IntPtr hWnd, IntPtr lParam);

static IEnumerable<IntPtr> EnumerateProcessWindowHandles(int processID)
{
List<IntPtr> handles = new List<IntPtr>();

EnumThreadDelegate addWindowHandle = delegate(IntPtr hWnd, IntPtr param)
{
handles.Add(hWnd);
return true;
};

foreach (ProcessThread thread in Process.GetProcessById(processID).Threads)
{
EnumThreadWindows(thread.Id, addWindowHandle, IntPtr.Zero);
}
return handles;
}
thanks!
 
That code is using a true anonymous method, which never existed in VB. Assuming .NET 3.5 or later, you can use a Lambda expression instead or a standard method. As VB didn't support multiline Lambdas until 2010, you have no choice but to use a standard method. As a result, you can't declare `handles` as a local variable in the EnumerateProcessWindowHandles method, because it will need to be accessible in the other method too.

Note also that `Handles` is a keyword in VB so, if you want to use it as an identifier, you have to escape it.
 
Back
Top