The language c#
2
The Language C#
C# (pronounced: see sharp) is Microsoft's new programming language for the
.NET platform. Although .NET can also be programmed in many other languages
(for example, Visual Basic .NET, or C++) C# is Microsoft's preferred language; it supports .NET best and is best supported by .NET.
C# is not a revolutionary new language. It is more a combination of Java, C++ and Visual Basic. The aim has been to adopt the best features of each of these languages while avoiding their more complex features. C# has been carefully developed by a small team lead by Anders Hejlsberg . Hejlsberg is an experienced language expert. At Borland he was the chief designer of Delphi. He is known to design his languages with the needs of practitioners in mind.
In this chapter we assume that the reader already has some programming experience, preferably in Java or C++. While we are explaining the concepts of C# we will also compare them with Java and C++.
2.1
Overview
Similarities to Java
At first sight C# programs look much like Java programs. Any Java programmer should be able to read them. As well as having almost identical syntax the following concepts have been carried across from Java:
K Object-orientation. Like Java, C# is an object-oriented language with single
inheritance. Classes can inherit from just one base class but can implement several interfaces.
K Type safety. C# is a type-safe language. Programming errors that arise from incompatible types in statements and expressions are detected by the compiler. There is no arbitrary pointer arithmetic and no unchecked type casts as in C++. At run time there are checks to ensure that array indices lie in the appropriate range, that objects are not referenced via uninitialized pointers and that a type cast leads to a well-defined result.
16
2
The Language C#
K Garbage collection. Dynamically allocated objects are not released by the
K
K
K
K
programmer, but