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.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,295
Location
Sydney, Australia
Programming Experience
10+
Conversion of C# lambdas to VB lambdas is quite simple. This:
Code:
arg => returnValue
becomes this:
Code:
Function(arg) returnValue
while this:
Code:
arg => action
becomes this:
Code:
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:
Code:
Function(arg)
    Return returnValue
End Function
Code:
Sub(arg)
    action
End Sub
 
Top Bottom