Why you should move to C#
Published: 07 Nov 2002 11:13 GMT

If you are moving to .Net and you already know C++ or Java, C# is a logical choice. However, if you are undecided about .Net, you might wonder why you'd want to move to C# rather than stick with your COM-based C++. Often the decision to move to .Net is based on factors other than learning C#, but C# does offer advantages over any COM-based language, thanks to the .Net Framework. This article examines 10 reasons to make the move to C#.
Modernised language
C# is a modernised version of C++. Originally you had the language C, which was widely used. C++ came about to add object-orientation to C, and C++ became the language of building "real" applications for Windows (according to the C++ developers.) C++ was used for writing the infrastructure and low-level applications, while Visual Basic developers wrote business applications.
C# brings the rapid development model of VB to the world of C++ developers, with some obvious changes. C# takes advantage of the .Net Framework, which means you have access to a powerful forms engine, just like VB developers have had for years. New data types have been added, such as the decimal data type for performing financial calculations.
Type-safety
C# is type-safe, which means several things. For example, you cannot use uninitialised variables. In C++ it is easy to declare a variable and then check its value; whatever was in the memory address given to that variable would then be shown, and this could wreak havoc on an application. The C# complier will notify you if you try to use a variable before you have initialised it to some valid value.
With C#, you can no longer just walk past the end of an array, as you have been able to do in C and C++ for ages. In C++ you could declare an array of three elements and then happily examine the fourth element of that array and get the next chunk of memory.
Object-oriented
While many would argue that C++ is object-oriented, C# goes to another level. Even simple data types can be treated as objects, meaning that an int has methods associated with it. For example, you can use the ToString method to get a string value for an int, as shown below. int Counter=14;
Console.Write(Counter.ToString());
In addition, literal strings can be treated as objects and support a variety of methods, such as Trim, ToUpper, ToLower, and many others, as shown here:
Console.Write("hello, world".ToUpper());
Simplified syntax
While C++ is an extremely powerful language, it has not typically been considered easy. C# attempts to simplify the syntax to be more consistent and more logical while also removing some of the more complex features of C++. For example, C# does away with pointers. As a type-safe language, C# doesn't allow direct memory manipulation, so pointers are no longer needed in C#.
Header files have also been removed from C#. The namespace and reference operators, :: and -> respectively, have been replaced with a single operator, the period (.).
Perhaps one of the biggest changes is that the int and bool data types are now completely different. This means that you will finally have an end to the assignment vs. comparison problem in if statements. In other words, the following code will not even compile under C#:
int Counter=14;
if (Counter=14) { //do something }
Attempting to compile this code will return an error stating:
Cannot implicitly convert type 'int' to 'bool'
C# also removes memory management issues from the developer by using .Net's garbage collection scheme. Items no longer referenced are marked for garbage collection, and the Framework can reclaim this memory as needed.








