Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

C#

Although some would argue that C# is Java-based, it is primarily rooted in C++. There have been some restrictions and a lot of cleanup in the language in the transition. C# has also been VB-ified to a large degree, which made it simpler and more productive to use than its ancestor C++.

Although they do differ, C# and Visual Basic .NET are very much alike. If you master one, it's quite easy to use the other. A lot of your time investment will be put in the Base Class Library (BCL) and, because it is shared by both C# and Visual Basic .NET, you don't have to spend time relearning its concepts.

C# Versus Visual Basic .NET

The differences between C# and Visual Basic .NET are mostly to suit different programmer's backgrounds. Unfortunately, there are some other differences. The following is a list (other than those that were mentioned when I discussed Microsoft's "going back") of some examples of the differences between C# and Visual Basic .NET6:

  • C# warns you if a function is missing a return statement—This catches a few bugs automatically.

  • C# requires XML-tagged documentation to be written in the code—Seems to be a good idea to drag out the comments from the code and use it for different scenarios.

  • C# can switch to Unmanaged mode—This can easily be achieved in Visual Basic .NET by just calling a C# class that takes care of it. Still, I find it nice to have the same possibilities in both environments.

  • You can use Using() in C# to tell that an object should be automatically Dispose()ed when going out of scope—That is very handy, for example, for connection and file objects that you don't want to wait for being garbage collected.

To be fair, Visual Basic .NET has some advantages over C# too:

  • Visual Basic .NET differs Inherits from Implements—In C#, it's written in both cases with a colon.

  • The event syntax is simple in Visual Basic .NET—It's as clean and intuitive as in VB6. In C#, you have to take care of more by hand.

  • Visual Basic .NET is not case sensitive—This is a matter of taste, but I prefer non–case sensitive. Otherwise, there is always somebody that will have two methods in a single class named something like getData() and GetData().

NOTE

Despite the differences between C# and Visual Basic .NET, you can use this book with either C# or Visual Basic .NET. The book is probably more "direct" if you have your background in VB6, because that is what I have too. I think and reason more as a VB programmer than as a C++ programmer.

  • + Share This
  • 🔖 Save To Your Account