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
milani_lucieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Abdurahman AlmatrodiBusiness DevelopmentCommented:
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)
0
milani_lucieAuthor Commented:
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
0
Wayne Taylor (webtubbs)Commented:
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
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

milani_lucieAuthor Commented:
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
0
Abdurahman AlmatrodiBusiness DevelopmentCommented:
Just change it to
Dim y = New Integer() { 123, 236, 389 }
0
Wayne Taylor (webtubbs)Commented:
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
0
dnwxCommented:
you can always use this site to convert from VB.NET to C# and vice-versa.
http://www.carlosag.net/Tools/CodeTranslator/
0
Wayne Taylor (webtubbs)Commented:
dnwx - did you try it? You'll find that that converter fails to convert it properly also.

Wayne
0
dnwxCommented:
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.
0
CodeCruiserCommented:
How about

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

How about

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

This does NOT work. Any pointers ?

Thanks
0
Abdurahman AlmatrodiBusiness DevelopmentCommented:
I did give you the solution and I tested. It is working Dim y = New Integer() { 123, 236, 389 }  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.