Dave Noderer's Blog

South Florida does .NET!

  Home  |   Contact  |   Syndication    |   Login
  203 Posts | 0 Stories | 363 Comments | 28 Trackbacks

News

Twitter












Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

.NET Community

Life at the Beach

My Blog Friends

I am converting some of the APIMASH projects from c# to vb.net and having to translate between the two.

You can find the APIMASH projects at: https://github.com/apimash/StarterKits

This is part of inheriting behavior of the System.Net.WebClient, for Windows Phone 8.

The c# code looks like this:

DownloadStringCompleted += (s, e) =>
{
    if (e.Error == null)
    {
        tcs.TrySetResult(e.Result);
    }
    else
    {
        tcs.TrySetException(e.Error);
    }
};

I tried two c# to vb.net conversion tools, DevFusion: http://www.developerfusion.com/tools/convert/csharp-to-vb/ and Telerik thttp://converter.telerik.com/.

Simple code converts fine but this example that does not, both do the same thing, could be the same engine:

DownloadStringCompleted += Function(s, e)
                               If e.[Error] Is Nothing Then
                                   tcs.TrySetResult(e.Result)
                               Else
                                   tcs.TrySetException(e.[Error])
                               End If

                           End Function

The lambda function works ok but that is not how event handlers are written in vb.net, this works much better:

AddHandler DownloadStringCompleted, Function(s, e)
                                        If e.[Error] Is Nothing Then
                                            tcs.TrySetResult(e.Result)
                                        Else
                                            tcs.TrySetException(e.[Error])
                                        End If
                                    End Function

posted on Sunday, August 25, 2013 7:59 PM

Feedback

# c# to vb.net Adding handlers with lambdas 1/6/2014 7:23 AM sriram
Really helps me to update my knowledge in Adding handlers with lambdas

# re: c# to vb.net Adding handlers with lambdas 1/6/2014 7:29 AM archana
helping to finish my project earlier

Post A Comment
Title:
Name:
Email:
Comment:
Verification: