how can I convert the following code from C# to VB without exposing “variable” as global variable.
private void SomeMethod(SomeType variable)
{
this.SomeEvent+= delegate
{
if (variable == 1)
{
this.DoSomething();
}
}
//here I have some other code
}
One possible solution
I just tried that and it works like a charm, so i don’t know why u say it doesnt 🙁 Visual studio 2010.
You can also do something like this
Delegate.Combine have exactly the same effect as AddHandler.
I don’t have visual studio 2008 so I don’t know how to write that in VS2008, try the second solution, the first seems to work only on 2010.
If this doesn’t work you can try this out, more code to write:
Visual studio syntactic sugar does something like this with anonymous delegate.