Question Converting a C# Lambda expression to VB.NET

njsokalski

Well-known member
Joined
Mar 16, 2011
Messages
102
Programming Experience
5-10
I will probably sound like a bad developer here, but I am attempting to convert some code from the following page from C# to VB.NET:

http://msdn.microsoft.com/en-us/library/hh286407(v=VS.92).aspx

The code I am having trouble converting is from Step 4 of "Joining a Multicast Group" on the page, and here is the code with the comment lines removed:

private void Join()
{
_receiveBuffer = new byte[MAX_MESSAGE_SIZE];
_client = new UdpAnySourceMulticastClient(IPAddress.Parse(GROUP_ADDRESS), GROUP_PORT);
_client.BeginJoinGroup(
result =>
{
_client.EndJoinGroup(result);
_client.MulticastLoopback = true;
_joined = true;
Send("Joined the group");
Receive();
}, null);
}

Any help would be greatly appreciated. Thanks.
 
Conversion of C# lambdas to VB lambdas is quite simple. This:
VB.NET:
arg => returnValue
becomes this:
VB.NET:
Function(arg) returnValue
while this:
VB.NET:
arg => action
becomes this:
VB.NET:
Sub(arg) action
In that case the lambda doesn't return anything so you would use Sub rather than Function. Also, that is a multine lambda, which would look like this in VB:
VB.NET:
Function(arg)
    Return returnValue
End Function
VB.NET:
Sub(arg)
    action
End Sub
 
Back
Top