SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Visual Basic 9: Standing Proud

rated by 0 users
This post has 16 Replies | 3 Followers

Top 10 Contributor
Posts 884
 icelava wrote:
VB C#
        Console.Write("Enter first number: ")
        Dim first = Integer.Parse(Console.ReadLine())
        Console.Write("Enter second number: ")
        Dim second = Integer.Parse(Console.ReadLine())

        If (first <= second) Then
            Console.WriteLine("First number lesser or equal.")
        Else
            Console.WriteLine("Second number greater.")
        End If
            Console.Write("Enter first number: ");
            int first = int.Parse(Console.ReadLine());
            Console.Write("Enter second number: ");
            int second = int.Parse(Console.ReadLine());

            if (first <= second)
                Console.WriteLine("First number lesser or equal.");
            else
                Console.WriteLine("Second number greater.");

Try
  Dim first as Integer
and
  Dim second as Integer

and check the IL code again. Smile [:)]

In VB.Net, if you do not specify the type, you get the default Object type, which needs to be boxed. Recall in the earlier incarnations of VB, you have Variant.. In some sense, it is analogous.

and you should see the boxing is gone.

Top 10 Contributor
Posts 2,284
Ah..... the joys of late type-binding. I remember having an "easy" programming experience the first time I started my development career with VB, then having a short tough period of cold turkey getting into the habit of explicit type casting when switching to C#.

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Page 2 of 2 (17 items) < Previous 1 2 | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems