Welcome to Learning C# 3.0. We're here to teach you the C# language from the ground up. If you've never done any programming before, in any language, start here in Chapter 1, and we'll have you writing real working applications in no time flat—before you reach the end of this chapter. If you have a little programming background in VB 6, PHP 4, or another non-object-oriented language, you'll find a lot in this book that's familiar, but also a lot that's new. You'll probably find the code in the first few chapters to be recognizable, but you may want to read the chapters anyway to get the hang of the syntax. Classes and objects are at the core of how C# works, though, so we'll get to those quickly, once we've covered the basics.
To start at the very beginning, C# is a modern language created by Microsoft as part of its .NET platform of languages. .NET is a layer of software that makes it easier for you to write programs that can communicate with the operating system (in this case, Windows). As the name implies, C# has its roots in C++, but over three versions, it has evolved its own techniques and elements that make it distinct. Most important, C# has the backing of the .NET Framework behind it, which we'll get into shortly. We're not going to assume that you have any C++ experience, so we won't frame our discussions of C# in terms of C++, or any other programming language. What you need to know right now is that you can write applications in C# that will do just about anything you need to do. You can write applications to manage your company's inventory (interacting with a database); you can write applications to analyze documents; you can write games; you can create an entire operating system in C# if you have a mind to. The .NET Framework allows C# to operate seamlessly with Windows, and take advantage of the familiar Windows features that users all over the world already know. You can also create C# applications that you can use on the Web, in much the same way.
To be completely honest, most modern object-oriented languages are rather similar underneath. The choice of one over the other is usually just a matter of personal preference. C# and Visual Basic have the advantage of the .NET Framework, but third-party languages can interact with the framework, too. C#'s similarity to C++ and Java makes it easy to learn for programmers familiar with those languages, but it's also easy to learn as your first language. Once you have the basics of C# down, you'll find it much easier to learn any other language you want to.
Unless we specifically say otherwise, when we refer to C# in this book, we mean C# 3.0; when we refer to .NET, we mean the .NET 3.5 Framework; and when we refer to Visual Studio, we mean Visual Studio 2008. We could spend some time telling you about the cool new features of C# 3.0 over its predecessors—and we're pretty excited about them—but if you're new to the language, it's all new to you, so there's little point in calling attention to specific features.
Finally, when we refer to using Visual Studio 2008, you may be using Visual C# 2008 Express Edition instead. C# Express is the free version of Visual Studio, designed for students and home users, but that doesn't mean it's a toy. In fact, the examples in this book were written and tested using C# Express. C# Express has the same compiler and libraries as Visual Studio, and within the examples in this book, you won't find any significant differences. There are some small differences in look and feel, or in feature names, and any time those come up, we'll mention them.
Visual C# 2008 Express Edition has all the features you'll need for the examples in this book, and it has the additional advantage of being completely free from Microsoft. Getting C# Express is very simple—just go here:
Here, you'll find download links for each of the free Visual Studio 2008 Express Editions. Scroll down to the Visual C# box (it's the green one), select your language, and click the Download link. Save the installer to your hard drive, and then run it. Most of the installation is pretty standard, but there is one step you should pay attention to, shown in Figure 1-1: the installation options.
The MSDN Library contains useful help files, and if you have the space available, you should install it, but it's not strictly necessary for this book. The second option, Microsoft SQL Server 2005 Express Edition, allows you to access databases with your code. You won't need it for a while if you're reading this book straight through, but we do use it in Chapters Chapter 20 and Chapter 21, so you may want to install it now. (You can install it separately later, if you want.) The Silverlight runtime is an amazing new technology from Microsoft, but we won't be covering it in this book, so you can skip that.
Figure 1-1. During the C# Express installation, select the MSDN Library if you have the space and the SQL Server 2005 Express option if you want to work through the data examples in Chapters Chapter 20 and Chapter 21.
The rest of the installation is mostly automatic. When you're done, you'll find a link in your Start menu, ready to go.
We'll give you a full tour of Visual Studio and C# Express in the next chapter. For this chapter, we'll tell you exactly what to do and when. Right now, we'll look a little more closely into the .NET platform to get you started, and then it'll be time to write some code.