[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

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
0
milani_lucie
Asked:
milani_lucie
  • 3
  • 3
  • 3
  • +2
1 Solution
 
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)AstronautCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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)AstronautCommented:
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)AstronautCommented:
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now