Results 1 to 5 of 5

Thread: C# to VB.NET conversion

  1. #1
    Join Date
    Jul 2011
    Posts
    2

    C# to VB.NET conversion

    Hi All,
    I am converting a C# Web Application to VB.NET. The problem occurs with the line of code in Bold. I am unable to find a VB.NET equivalent of this line.


    ArrayList arrSymbologies = new ArrayList();

    // get all public static properties
    PropertyInfo[] propertyInfos;
    propertyInfos = typeof(BarCodeReadType).GetProperties(BindingFlags .Public |
    BindingFlags.Static);
    // sort properties by name
    Array.Sort(
    propertyInfos, delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
    { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); }
    );


    ​I tried different online (free) C# to VB.NET converters, they convert is as follows, but the Visual studio give errors (BC30201: Expression expected. ; BC32017: Comma, ')', or a valid expression continuation expected.)

    Array.Sort(propertyInfos, Function(propertyInfo1 As PropertyInfo, propertyInfo2 As PropertyInfo) propertyInfo1.Name.CompareTo(propertyInfo2.Name))

    Please help in this regard.
    Thanks in Advamce
    Babar

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: C# to VB.NET conversion

    Check the corrections done:

    Code:
    using System.Reflection;  // reflection namespace
    
    // get all public static properties of MyClass type
    PropertyInfo[] propertyInfos;
    propertyInfos = typeof(MyClass).GetProperties(BindingFlags.Public |
                                                  BindingFlags.Static);
    // sort properties by name
    Array.Sort(propertyInfos,
            delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
            { return propertyInfo1.Name.CompareTo(propertyInfo2.Name); });
    
    // write property names
    foreach (PropertyInfo propertyInfo in propertyInfos)
    {
      Console.WriteLine(propertyInfo.Name);
    }

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Re: C# to VB.NET conversion

    I am sorry if I misinterpreted. The source code that you provided, I need to convert this into VB.NET.

    Can you please provide me the VB.NET equivalent of this source?

  4. #4
    Join Date
    Apr 2010
    Posts
    219

    Re: C# to VB.NET conversion

    You can try going here and the service provided over there will translate the code for you, just start typing the code or upload a file to convert it. Hope that helps you out.

  5. #5
    fiedel Guest

    Re: C# to VB.NET conversion

    First, make sure you're using a recent version of Visual Studio. VB .NET didn't have full anonymous method support until 2010, but 2008 might be sufficient. The problem is VB won't let you go straight from the anonymous method (which would be Func(Of PropertyInfo, PropertyInfo, Integer)) to Comparison(Of T), whereas C# had a bit of syntax to help with that conversion. You can address it by storing the lambda in a variable:

    Dim comparison As Comparison(Of PropertyInfo) = Function(left As PropertyInfo, right As PropertyInfo)
    Return left.Name.CompareTo(right.Name)
    End Function

    Array.Sort(propertyInfos, comparison)

Similar Threads

  1. OST to PST Conversion
    By avvia in forum Windows Software
    Replies: 7
    Last Post: 08-10-2013, 02:51 AM
  2. Mac Pro ATX Conversion
    By Intellecturator in forum Hardware Peripherals
    Replies: 3
    Last Post: 22-03-2011, 07:36 AM
  3. Wav to AC3 5.1 conversion
    By Lalitmohan in forum Windows Software
    Replies: 7
    Last Post: 20-07-2010, 02:52 PM
  4. conversion bug from WMA to MP3
    By Ebenezer in forum Windows Software
    Replies: 3
    Last Post: 16-03-2009, 02:24 PM
  5. ppt to pdf/doc conversion possible?
    By vitrag24 in forum Windows Software
    Replies: 4
    Last Post: 15-10-2008, 03:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,527,459.82680 seconds with 17 queries