Monday, December 3, 2007

C# 2005

Introduction


The C# programming language is a powerful, relatively new descendant of the earlier C, C++, and Java languages. Programming with it is a lot of fun, as you’re about to find out in this book.

Microsoft created C# as a major part of its .NET initiative. For what are proba­bly political reasons, Microsoft turned the specifications for the C# language over to the ECMA (pronounced ek-ma) international standards committee in the summer of 2000, long before .NET was a reality. In theory, any company can come up with its own version of C# written to run on any operating system, on any machine larger than a calculator.

When the first edition of this book came out, Microsoft’s C# compiler was the only game in town, and its Visual Studio .NET suite of tools offered the only way to program C# (other than at the Windows command line). Since then, however, Visual Studio has gone through two major revisions — Visual Studio 2003 and, very recently, Visual Studio 2005. And at least two other players have entered the C# game.

It’s now possible to write and compile C# programs on a variety of Unix-based machines using either the Mono or Portable .NET implementations of .NET and C#:

*. Mono (www.go-mono.com) is an open-source software project spon­sored by Novell Corporation. Version 1.1.8 came out in June 2005. While Mono lags Microsoft’s .NET, just now implementing the 1.1 version that Microsoft released a couple of years ago, it appears to be moving fast.

*. Portable .NET, under the banner of Southern Storm Software and DotGNU (www.dotgnu.org/pnet.html), is also open-source. Portable .NET is at version 0.7.0 as of this writing.

Both Mono and Portable .NET claim to run C# programs on Windows and a variety of Unix flavors, including Linux and Apple’s Macintosh operating system. At this writing, Portable .NET reaches the greater number of flavors, while Mono boasts a more complete .NET implementation. So choosing between them can be complicated, depending on your project, your platform, and your goals. (Books about programming for these platforms are becoming available already. Check www.amazon.com.)

Open-source software is written by collaborating groups of volunteer pro­grammers and is usually free to the world.Making C# and other .NET languages portable to other operating systems is far beyond the scope of this book. But you can expect that within a few years, the C# Windows programs you discover how to write in this book will run on all sorts of hardware under all sorts of operating systems — matching the claim of Sun Microsystems’ Java language to run on any machine. That’s undoubtedly a good thing, even for Microsoft. The road to that point is still under construction, so it’s no doubt riddled with potholes and obstacles to true universal portability for C#. But it’s no longer just Microsoft’s road.

For the moment, however, Microsoft’s Visual Studio has the most mature versions of C# and .NET and the most feature-filled toolset for programming with them. If all you need is C#, I’ve included a bonus chapter called “C# on the Cheap” on the CD that accompanies this book. That chapter tells you how you can write C# code virtually for free. (You’ll be missing lots of amenities, including the nice visual design tools that Visual Studio 2005 provides, but you can write Windows code without them, especially the kind of code in this book. Bonus Chapter 5 explains how.)

Note: Two authors wrote this book, but it seemed more economical to say “I” instead of “we,” so that’s what we (I?) do throughout.

What’s New in C# 2.0

While C# version 2.0 does have a number of small changes here and there, most of C# 2.0 is still virtually the same as the previous version. The big new additions that this book covers include the following:

*. Iterator blocks: An iterator is an object that lets you step through all the items in a collection of objects. That’s always been possible, but C# 2.0 makes it far simpler to implement. Bonus Chapter 3 on the CD helps you take advantage of the simplicity and flexibility of iterator blocks. Chapter 15 covers collections.

*. Generics: This is the big one! Generic features allow you to write highly general, more flexible code. It’s a powerhouse — a programmer’s dream. Chapter 15 shows you how to write far simpler and more type-safe code using generics.
Leaving aside a few of the more esoteric and advanced additions, we’ll men­tion a few smaller items here and there as appropriate. (Don’t worry if parts of this Introduction are Greek to you. You’ll get there.)

About This Book

The goal of this book is to explain C# to you, but to write actual programs you need a specific coding environment. We’re betting that most readers will be using Microsoft Visual Studio, although we do provide alternatives. In basing the book on Visual Studio, we’ve tried to keep the Visual Studio portions to a reasonable minimum. we could just tell you, “Run your program any way you want,” but instead we may say, “Execute your C# program from Visual Studio by pressing F5.” We want you to be able to focus on the C# language and not on the mechanics of getting simple things to work.

We realize that many, if not most, readers will want to use C# to write graphi­cal Windows applications. C# is a powerful tool for programming graphical Windows applications, but that’s only one area for using C#, and this book must focus on C# as a language. We touch briefly on graphical Windows pro­grams in Chapter 1, but you should get a good grasp of C# before seeking another source to understand Windows programming in full. We also realize that some power users will be using C# to build Web-ready, distributed appli­cations; however, publishing limitations require us to draw the line some­where. C# 2005 For Dummies does not tackle the challenges of distributed programming. The book does explain quite a bit of .NET, though, for the simple reason that much of C#’s power comes from the .NET Framework class libraries that it uses.

At a minimum, you need the Common Language Runtime (CLR) before yoi can even execute the programs generated by C#. Visual Studio 2005 copie: the CLR onto your machine for you as part of the installation procedure. Alternatively, you can download the entire .NET package, including the C# compiler and many other nice tools, from Microsoft’s Web site at http:// msdn.microsoft.com. Look for the .NET Software Development Toolkit (SDK). Bonus Chapter 5 on the CD explains how to get these items.

You can still create most of the programs in this book with Visual Studio 2003, if you need to. The exceptions are those that cover the new features available only with C# 2.0, primarily generics and iterator blocks. A less-costly C# Express 2005 version of Visual Studio 2005 is also available, and don’t overlook the cheap options covered in Bonus Chapter 5 on the CD.

What You Need to Use the BookHow to Use This Book

We’ve made this book as easy to use as possible. Figuring out a new language is hard enough. Why make it any more complicated than it needs to be? The book is divided into six parts. Part I introduces you to C# programming with Visual Studio. This part guides you step by step in the creation of two differ­ent types of programs. We strongly encourage you to start here and read these two chapters in order before branching out into the other parts of the book. Even if you’ve programmed before, the basic program framework created in Part I is reused throughout the book.

The chapters in Parts II through V stand alone. We have written these chapters so that you can open the book to any one of them and start reading. If you’re new to programming, however, you will have to read Part II before you can jump ahead. But when you return to refresh your memory on some particular topic, you should have no trouble flipping to a section without the need to restart 20 pages back. Of course, the Part of Tens finishes out the lineup, and there’s more on the CD that accompanies the book.
How This Book Is Organized

Here’s a brief rundown on what you’ll find in each part of the book.

Part I: Creating Your First C# Programs

This part shows you, step by step, how to write the smallest graphical Windows application possible using the Visual Studio 2005 interface. Part I also shows you how to create the basic nongraphical C# framework that’s used in the other parts of this book.

Part II: Basic C# Programming

At the most basic level, Shakespeare’s plays are just a series of words all strung together. By the same token, 90 percent of any C# program you ever write consists of creating variables, performing arithmetic operations, and controlling the execution path through a program. This part concentrates on these core operations.
Part III: Object-Based Programming

It’s one thing to declare variables here or there and to add them and subtract them. It’s quite another thing to write real programs for real people. Part III focuses on how to organize your data to make it easier to use in creating a program.
Part IV: Object-Oriented Programming

You can organize the parts of an airplane all you want, but until you make it do something, it’s nothing more than a collection of parts. It’s not until you fire up the engines and start the wings flapping that it’s going anywhere.

In like fashion, Part IV explains how to turn a collection of data into a real object — an object that has internal members, sure, but an object that can mimic the properties of a real-world item. This part presents the essence of object-oriented programming.
Part V: Beyond Basic Classes

After the airplane gets off the ground, it has to go somewhere. Figuring out classes and the fundamentals of object-oriented programming is only a start. Part V takes the next step, introducing structures, interfaces, and generics, your gateway to more advanced object-oriented concepts — and the wild blue yonder.

Part VI: The Part of Tens

C# is great at finding errors in your programs — at times, it seems a little too good at pointing out my shortcomings. However, believe it or not, C# is trying to do you a favor. Every problem it finds is another problem that you would otherwise have to find on your own.

Unfortunately, the error messages can be confusing. One chapter in this part presents the ten most common C# build error messages, what they mean, and how the heck to get rid of them. Many readers are coming to C# from another programming language. The second chapter in The Part of Tens describes the ten major differences between C# and its progenitor, C++.

Read Comments For More

1 comments:

Anonymous said...

http://rapidshare.com/files/64859980/C__2005_For_Dummies__2006_.pdf

or

http://tinyurl.com/3d5fb6

Would you like to get my updates directly to your mailbox? Click below to Enter your mail address

Subscribe to Books Tube


AddThis Feed Button 
Page copy protected against web site content infringement by Copyscape