Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596521073/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
Congratulations! You've decided to learn to program. Maybe you're learning it for a class, maybe you're learning it to get ahead at work, or maybe you're learning it just for fun. Whatever the reason, we've written this book to help you learn C#. You don't need a language reference, or a code analysis book; you want to start from square one and learn to program. In that respect, your desire to learn how to program is more important than which specific language you choose. There are plenty of modern languages out there, and lots of them are quite similar, under the hood.
Why, out of all the languages you could learn, should you pick C#? There are several good reasons:
C# is the preferred language for use with Microsoft's .NET platform. That means C# was created for writing Windows applications, and as you know, the majority of the world's computers run Windows.
C# is supported by Visual Studio and its counterpart, Visual C# Express. Visual Studio makes writing code easier and faster in hundreds of different ways. And did we mention C# Express is free?
C# is designed to be powerful enough to write serious business applications, but simple enough to be easy to learn. C# was influenced by the older, and hugely popular, languages C++ and Java, but was intended to bring all the good features of those languages without the quirks that they've acquired over the years.
So, although there are plenty of languages you could learn, we think that C# is an excellent choice to start with.
We could tell you about the new features of C# 3.0, or why we enjoy programming in C# after learning C++, but we suspect most of that won't matter to you. We wrote this book for people with no experience with C# or any other programming languages, so the differences between C# 2.0 and C# 3.0 probably don't impress you much. What we can tell you is that C# 3.0 means that the Microsoft .NET team has been refining the language since 2000, and we think the result is a stable, powerful, easy-to-learn language. We commend you on your choice to learn C#, and we'll try to make the experience as smooth as possible.
About This Book
Learning C# 3.0 is an introductory book. We don't assume that you have any prior programming experience, so we start with the very basic fundamentals of the language. We take it slowly and steadily, one concept per chapter, each one building on the last. We don't shy away from the complicated stuffwe introduce object-oriented programming in , and we use object-oriented concepts from there on out. By the latter half of the book, we'll be using intermediate topics like interfaces and delegates, building on what you've already learned. We finish up with two chapters on Windows programming, and two chapters on data, which is the interesting stuff that everybody wants to know about.
The goal of the book is not to get you to write fancy applications without understanding what they do. Our goal is to give you a good grasp of the basics of the language. Once you have that down, you can pick up a more advanced C# book and get the full benefit from it (and of course, we recommend O'Reilly's excellent line of C# books). Even better, once you've learned to think in a modern, object-oriented language, it becomes that much easier to learn others. The first programming language is always the hardest to learn; once you've learned C#, learning Visual Basic, or Java, or PHP is mostly just a matter of translating what you already know.
When you're learning a new language, clear, concise explanations are always helpful, and we've got those. Example applications that you can work through yourself are critical, and we have those too. But what really cements the language in your mind is practice, practice, practice, which we'll provide in each chapter. We've spent a lot of time coming up with quiz questions and exercises that underscore what you'll learn in each chapter, and give you the confidence that comes from writing your own code.
Who This Book Is For
We wrote Learning C# 3.0 for people with no programming experience at all. If you're a student just starting to learn to program, this book is for you. If you have some experience with web design or system administration, and you want to learn about programming, this book is for you. If you're learning on your own because you want to know what this programming thing is all about, good for you! We'll help you get there.
If you already know another programming language, but you haven't run into object-oriented concepts yet, the material in Chapters is where it'll get really interesting for you. If you're familiar with C++, you'll find a lot of the syntax in this book familiar, but there's a lot that's new as well (you can say goodbye to pointers, for one thing), so we suggest that you at least skim the early chapters. If have some experience with another language such as Visual Basic, Java, or Ruby, there's a lot here that you'll be familiar with, but with enough syntax differences to trip you up if you're not careful.
If you're proficient in another object-oriented language and you're looking to pick up the changes as you transition to C#, we suggest you look into this book's companion volume, Programming C# 3.0, by Jesse Liberty and Donald Xie. That book assumes that you have some programming experience already and ramps up to the complex stuff more quickly.
How This Book Is Organized