Introduction to C# Basics

Microsoft .net was formerly known as Next Generation Windows Services (NGWS for short). It is a completely new platform for developing the next generation of windows/web applications. These applications would transcend device boundaries and fully harness the power of the Internet. However, this new platform required a language which could take its full advantage; this is one of the factors that led to the development of C#. C# has evolved from C/C++. Hence, it retains its family name. The # (hash symbol) in musical notations is used to refer to a sharp note and is called “Sharp”, hence the name is pronounced as C Sharp.

The .net platform supports more than 20 different languages and the list is growing every day. The C# compiler is considered to be the most efficient compiler in the .net family and a major part of the .net base classes libraries (which constitute a major part of .net) itself are written in C#.

Moreover, C# could be considered as a modern replacement for C/C++ languages. It gives access to many of the facilities previously available only in C++, while retaining some of the simplicity of Visual Basic. Though other languages have been plugged into the .net platform, C# was developed specifically for the new platform. All these reasons put together make C# the preferred choice of language for the .net platform.

It is important to look at C# not just as a programming language but as an integral part of the .net platform. The .net platform revolutionizes facilities available for Windows programming. It provides benefits like the automatic garbage collector for automatically cleaning up resources occupied by dead objects, and enhanced libraries that cover areas ranging from Windows GUI support to data access to generating ASP.net pages.

Another important feature of C# is that it is a real object-oriented programming language. This may not sound very exciting since we do have powerful programming languages like C++, and C# has its roots in C++. C++ though a well-designed object oriented language never actually enabled code re-use. Just to cite an example, in C++ you required access to the header files, where the original source code resided, in order to be able to inherit the classes contained within them. Moreover, C/C++ were full of pitfalls and even experienced programmers could blunder easily. As an example, just a missing break statement in a select case block could cause disaster. C# addresses all these problems and makes it a safer realm for both, the experienced and the inexperienced programmers.

The key point of C# however is that it enhances developer productivity and increases safety, by enforcing strict type checking. It features a garbage collector, which relieves the programmer of the burden of manual memory management. C# offers extensive interoperability. The managed environment is appropriate for most enterprise applications. Some applications do require “native” code, either for performance reasons or to interoperate with existing application programming interfaces (APIs). In such situations developers use C++ even when they would prefer to use a more productive and easier language. For example, the Windows API is written in C/C++. This forces the developers to use Visual C++ for system-level programming, even though they would prefer to use Visual Basic. C# addresses these problems by providing the simplicity and the productivity of Visual Basic while providing native support for the Component Object Model (COM) and Windows-based APIs. C# also allows restricted use of native pointers.

In the later posts we will be looking at the basic programming constructs of C# and the fundamental data types in C# namely value and reference types. We will also be looking at the concept of boxing and unboxing. And finally we will see how to write and compile a simple C# program.

Leave a comment