Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 07-07-2011
Member
 
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
Reply With Quote
  #2  
Old 07-07-2011
Member
 
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);
}
Reply With Quote
  #3  
Old 07-07-2011
Member
 
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?
Reply With Quote
  #4  
Old 08-07-2011
Member
 
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.
Reply With Quote
  #5  
Old 12-07-2011
fiedel
 
Posts: n/a
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)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C# to VB.NET conversion"
Thread Thread Starter Forum Replies Last Post
OST to PST Conversion avvia Windows Software 7 08-10-2013 02:51 AM
Mac Pro ATX Conversion Intellecturator Hardware Peripherals 3 22-03-2011 07:36 AM
Wav to AC3 5.1 conversion Lalitmohan Windows Software 7 20-07-2010 02:52 PM
conversion bug from WMA to MP3 Ebenezer Windows Software 3 16-03-2009 02:24 PM
ppt to pdf/doc conversion possible? vitrag24 Windows Software 4 15-10-2008 03:05 AM


All times are GMT +5.5. The time now is 04:23 PM.