Chapter 1. C# and .NET Programming

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.

Tip

If you’re a programmer migrating from Java or C++, you may find the material in Programming C# 3.0 by Jesse Liberty and Donald Xie (O’Reilly) a more appropriate fit for your skills.

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.

Get Learning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.