Link to home
Start Free TrialLog in
Avatar of milani_lucie
milani_lucieFlag for United States of America

asked on

Convert from C# to VB.NET - Framework 3.5

Hi,

Can you please provide me equivalent code in VB.NET which is working ?

var y = new[] { 123, 236, 389 };
Console.WriteLine(y[0]);
Console.WriteLine(y[1]);
Console.WriteLine(y[2]);
Console.WriteLine(y.GetType().Name);

Thanks
Avatar of Abdurahman Almatrodi
Abdurahman Almatrodi
Flag of Saudi Arabia image

Did you try some free converter sites. I did the with http://converter.telerik.com/ , and the result is: Dim y As var = New () {123, 236, 389}
Console.WriteLine(y(0))
Console.WriteLine(y(1))
Console.WriteLine(y(2))
Console.WriteLine(y.[GetType]().Name)
Avatar of milani_lucie

ASKER

What is this declaration ?

Dim y As var = New () {123, 236, 389}

This must be

Dim y = New () {123, 236, 389}   --- This is not correct (Error)

Thanks
Avatar of Wayne Taylor (webtubbs)
Almatrodi - if that's the code returned by the converter, you may want to try a different one, because it is wrong.

The VB.Net version is this...

        Dim y = New Object() {123, 236, 389}
        Console.WriteLine(y(0))
        Console.WriteLine(y(1))
        Console.WriteLine(y(2))
        Console.WriteLine(y.GetType().Name)

Wayne
Wayne,

Console.WriteLine(y.[GetType]().Name)

returns "Int32[]" in C#

Console.WriteLine(y.GetType().Name)

returns "Object[]" in VB.NET

I think so there is some thing wrong !

Thanks
Just change it to
Dim y = New Integer() { 123, 236, 389 }
Declaring an variable as 'var' in C# informs the compiler to determine the object type. VB.Net doesn't have an equivelent, so I explicitely used Object, but Almatrodi is correct - simply replace 'Object' with 'Integer'.

Wayne
Avatar of dnwx
dnwx

you can always use this site to convert from VB.NET to C# and vice-versa.
http://www.carlosag.net/Tools/CodeTranslator/
dnwx - did you try it? You'll find that that converter fails to convert it properly also.

Wayne
Webtubbs, I didn't really try it since I always use it.
Well, I'm sorry if it didn't work, but at least there's a tip for future needs.
How about

Dim y = New(){123, 236, 389}
CodeCruiser:

How about

Dim y = New(){123, 236, 389}

This does NOT work. Any pointers ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Abdurahman Almatrodi
Abdurahman Almatrodi
Flag of Saudi Arabia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial