General Discussion

I did a Google search on C# vs. VB.NET and by most accounts it is not too hard to switch from one to another. However, VB.NET is a lot more verbose and one would have to learn a lot more keywords compared to C# which more or less just replaces a lot of words with } and {.

If C# is too hard to pick up we may be able to do certain sub-projects in VB.NET and import them as DLLs into C# projects? I'm not really familiar with mixing the two but I'm sure they're possible seeing that they're both .NET. Of course, I would prefer to have it all in C#.

Also, if the current trend is anything to go by, industry values C# higher than VB.NET. So I think it would be much more valuable learning the C# syntax earlier than later, especially if you want to get into Computer Science as profession.

sohummisra added 0 Minutes and 48 Seconds later...


Give me an example of where you use it for me to make a better comment.
Yeah, I know all about C# syntax by now, its pretty similar to vb.net as a language and has a similar syntax to C++, that is not a problem. My problem was that the IDE for C# is a bit poorer than vb.net, and I haven't seen such extra keywords in vb.net lol. :p

Anyways, I think I'm cool with C# anyways, though vb.net could've been better, but then one can't win at everything! :p
 
Yeah, I know all about C# syntax by now, its pretty similar to vb.net as a language and has a similar syntax to C++, that is not a problem. My problem was that the IDE for C# is a bit poorer than vb.net, and I haven't seen such extra keywords in vb.net lol. :p

Anyways, I think I'm cool with C# anyways, though vb.net could've been better, but then one can't win at everything! :p
You are using Visual C# Express? What are your gripes with the IDE? I can see if there is another IDE out there that better satisfies your needs.
 
You are using Visual C# Express? What are your gripes with the IDE? I can see if there is another IDE out there that better satisfies your needs.
Yeah, Visual C# express, and don't worry, its probably the best. The problems are built in lol, as I said before, but Vb.net's IDE is much more flexible, plus in the coding portions, When you write something, you have a menu popup, saying possible options, so it sometimes became easier to write code, especially repeated and repeated code, because it could auto fill. And its on the spot debugging(In the code view itself), is much faster than C#'s IDE, and most of all, it gets away with all those { and }'s and ;'s lol, so the code looks much more neater IMO.
 
When you write something, you have a menu popup, saying possible options, so it sometimes became easier to write code, especially repeated and repeated code, because it could auto fill.

This happens in Visual C# Express, I think.
 
Give me an example of where you use it for me to make a better comment.

Code:
// Namespace Declaration
using System;

class mat
{
    public void addition()
    {
        int a,b,c;
        Console.Write("Enter 2 numbers : \n ");
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        Console.Write("\nSum = ");
        c = a + b;
        Console.Write("{0}\n", c);
        Console.ReadLine();
    }
    public void subtract()
    {
        int a, b, c;
        Console.Write("Enter 2 numbers : \n ");
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        Console.Write("\nDifference = ");
        c = a - b;
        Console.Write("{0}\n", c);
        Console.ReadLine();
    }
    public void multiply()
    {
        int a, b, c;
        Console.Write("Enter 2 numbers : \n ");
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        Console.Write("\nMultiplication = ");
        c = a * b;
        Console.Write("{0}\n", c);
        Console.ReadLine();
    }
    public void divide()
    {
        decimal a1, b1;
        Console.Write("Enter 2 numbers : \n ");
        a1 = decimal.Parse(Console.ReadLine());
        b1 = decimal.Parse(Console.ReadLine());
        if (b1 == 0)
        {
            Console.Write("Please Re-enter : ");
            b1 = decimal.Parse(Console.ReadLine());
        }
        Console.Write("\nDivision = ");
        decimal x;
        x = a1 / b1;
        Console.Write("{0}\n", x);
        Console.Write("\nRemainder = ");
        x = a1 % b1;
        Console.Write("{0}\n", x);
        Console.ReadLine();
    }
    public void remainder()
    {
        int a, b, c;
        Console.Write("Enter 2 numbers : \n ");
        a = int.Parse(Console.ReadLine());
        b = int.Parse(Console.ReadLine());
        if (b == 0)
        {
            Console.Write("Please Re-enter : ");
            b = int.Parse(Console.ReadLine());
        }
        Console.Write("\nRemainder = ");
        c = a % b;
        Console.Write("{0}\n", c);
        Console.ReadLine();
    }
}


class maths
{
    public static void Main()
    {
        mat abh = new mat();
        int choice;//, a, b, c;
a:      Console.Clear();
        Console.Write(" 1. Add \n 2. Subtract \n 3. Multiply \n 4. Divide \n 5. Remainder \n 6. Exit \n");
        Console.Write("Enter a choice : ");
        choice = int.Parse(Console.ReadLine());
        while (choice > 6 || choice < 1)
        {
            Console.Write("Please Re-Enter : ");
            choice = int.Parse(Console.ReadLine());
        }
            switch (choice)
            {
                case 1:
                    abh.addition();
                    goto a;
                    //break;

                case 2:
                    abh.subtract();
                    goto a;
                    //break;
                case 3:
                    abh.multiply();
                    goto a;
                    //break;
                case 4:
                    abh.divide();
                    goto a;
                    //break;
                case 5:
                    abh.remainder();
                    goto a;
                    //break;
                case 6:
                    Console.Write("Thank You for using. Bye! \n");
                    Console.ReadLine();
                    break;
                default: goto a;

            } // end of switch
     } // end of main
} // end of class math

A simple program to do basic mathematical calculations.

I have used goto, but I'm certain i could have avoided it. (was a bit lazy to think about the workaround)
 
Yeah, Visual C# express, and don't worry, its probably the best. The problems are built in lol, as I said before, but Vb.net's IDE is much more flexible, plus in the coding portions, When you write something, you have a menu popup, saying possible options, so it sometimes became easier to write code, especially repeated and repeated code, because it could auto fill. And its on the spot debugging(In the code view itself), is much faster than C#'s IDE, and most of all, it gets away with all those { and }'s and ;'s lol, so the code looks much more neater IMO.
Hehe, many of your qualms with C# are the very things I like about it. IMO, with indentation, the { and } provide a great way for dividing the code up in your head. As for autofill, I think intellisense is present in C# express as well, so I don't know why you don't get the popup menu. Try pressing CTRL+Space, maybe?

From what I understand VB.NET does background compilation on the code (something like Eclipse does for Java, I suppose), which is why you can debug in Code View. For larger projects this would become a problem.

sohummisra added 0 Minutes and 56 Seconds later...

It does, but in much lower numbers. Moreover it doesn't correct cases automatically, something vb.net does with ease.
That's because C# is case-sensitive. Correcting cases wouldn't make sense. ;)

sohummisra added 7 Minutes and 22 Seconds later...

A simple program to do basic mathematical calculations.

I have used goto, but I'm certain i could have avoided it. (was a bit lazy to think about the workaround)
You been doing too much assembly coding? That is exactly what a while loop compiles down to in machine code! You could rewrite it as follows:

Code:
class maths
{
    public static void Main()
    {
        bool loop = true;
        mat abh = new mat();
        int choice;//, a, b, c;
        while (loop)
        {
            Console.Clear();
            Console.Write(" 1. Add \n 2. Subtract \n 3. Multiply \n 4. Divide \n 5. Remainder \n 6. Exit \n");
            Console.Write("Enter a choice : ");
            choice = int.Parse(Console.ReadLine());
            while (choice > 6 || choice < 1)
            {
                Console.Write("Please Re-Enter : ");
                choice = int.Parse(Console.ReadLine());
            }
            switch (choice)
            {
                case 1:
                    abh.addition();
                    break;

                case 2:
                    abh.subtract();
                    break;
                case 3:
                    abh.multiply();
                    break;
                case 4:
                    abh.divide();
                    break;
                case 5:
                    abh.remainder();
                    break;
                case 6:
                    Console.Write("Thank You for using. Bye! \n");
                    Console.ReadLine();
                    loop = false;
                    break;
                default:
                    break;

            } // end of switch
        }
     } // end of main
} // end of class math

Even more common with input functions is to do while (true) and then do a callback to a unload function (if you need one) and then just System.Exit() (or whatever the exit function is--I forget. :p), since Console.ReadLine() probably waits. Using goto is a matter of choice in this case, since it probably compiles down to the same thing. Just gotta make sure its clear. From my vantage point I think a loop is clearer because what you are doing is looping until the user quits.
 
So, when you break out of each case (1 to 5), does it go back to the start of the while loop?
 
Yes. Basically, the break command exits the switch statement, and proceeds with whatever's next. In this case, its the while loop.
 
So, when you break out of each case (1 to 5), does it go back to the start of the while loop?
Yes. A break simply breaks out of the enclosing structure. So if you broke from within a switch structure, it would go to the next code after the switch. So:

Code:
int i = 1;
switch (i)
{
  case 0:
    // some code;
    break;

  case 1:
    // some code;
    break;
}

// would come here after switch statement
i = 2;

These are useful within loops (breaking out of a loop terminates it prematurely) and if-blocks. However, I will confess that I am not proficient in using breaks outside of the switch statement. :p
 
Thanks Sohum, this seems a perfect replacement for the label in this problem.
I was thinking of the while loop as well, but did not know about the boolean operator.
 
Just a question, guys. Are y'all using VC# 2008 or 2005 Express? I currently have VS2005 but can get VS2008 for free under academic licensing for myself if everyone else is on 2008 Express. It's 4gigs, though (unless my math was wrong), so I want to make sure before taking the plunge!
 

Users who are viewing this thread

Top