1. Introduction
The PDF of this document is available |HERE|.
The examples in this document are available |HERE|.
C# is a relatively new language. It was available in successive beta versions starting in 2000 before being officially released in February 2002 alongside Microsoft’s .NET 1.0 platform, to which it is tied. C# can only run within this runtime environment. This environment provides programs running within it with a very extensive set of classes. As a rough approximation, one could say that the .NET platform is a runtime environment analogous to a Java virtual machine. However, there are two notable differences:
- Java has run on various operating systems (Windows, Unix, Macintosh) since its inception. In 2002, the .NET platform ran only on Windows machines. For several years now, the Mono project [http://www.mono-project.com] has made it possible to use the .NET platform on operating systems such as Unix and Linux. The current version of Mono (February 2008) supports .NET 1.1 and elements of .NET 2.0.
- The .NET platform allows programs written in different languages to run. All that is required is for the compiler to be able to generate IL (Intermediate Language) code, which is executed by the .NET virtual machine. All .NET classes are available to .NET-compatible languages, which tends to blur the differences between languages to the extent that programs make extensive use of these classes. The choice of a .NET language becomes a matter of preference rather than performance.
In 2002, C# used the .NET 1.0 platform. At that time, C# was largely a “copy” of Java, and .NET was a class library very similar to that of the Java development platform. When learning the language, one could switch from a C# environment to a Java environment without feeling out of place. There were even tools available to convert source code from one language to the other. Since then, things have changed. Each language and each development platform now has its own specific features. It is no longer as straightforward to transfer skills from one domain to another.
C# 3.0 and the .NET 3.5 framework bring many new features. The most significant is probably LINQ (Language-Integrated Query), which allows you to query sequences of objects—whether from in-memory structures such as arrays and lists, databases (currently SQL Server only—as of February 2008), or XML files—in a uniform manner, similar to SQL.
This document is not a comprehensive course. For example, LINQ is not covered here. It is intended for people who already know how to program and want to learn the basics of C#. It is a revision of the original document published in 2002.
Several books helped me write this course:
For the 2002 version:
- Professional C# Programming, Wrox Publishing
- C# and .NET, Gérard Leblanc, Eyrolles
At the time, I found both of these books to be excellent. Since then, Gérard Leblanc has published updated versions, including the following:
- C# and .NET 2005, Gérard Leblanc, Eyrolles
For the 2008 revision, I used the following sources:
- the original 2002 document. This document, which was a copy-and-paste from my Java course, contained both typos and more serious errors, such as stating that primitive types like System.Int32 were classes when they are actually structures. My bad...
- the MSDN documentation for Visual Studio Express 2008
- the book *C# 3.0 in a Nutshell* by Joseph and Ben Albahari, published by O'Reilly, one of the best programming books I have ever read.
The source code for the examples in this document is available at [http://tahe.developpez.com/dotnet/csharp/].
The PDF of this document is available |HERE|.
Serge Tahé, May 2008
Since May 2008, C# has, of course, evolved. However, this document remains relevant for learning the language. As a supplement to this course, you will find a presentation of the Entity Framework ORM (Object Relational Mapper) in the article "Introduction to Entity Framework 5 Code First ORM" at the URL [http://tahe.developpez.com/dotnet/ef5cf/].
Serge Tahé, October 2013