Read an Excerpt
Welcome to C# 3.0 Unleashed, a programmer's guide and reference to the C# (pronounced "C sharp") programming language. C# is primarily an object-oriented programming language, created at Microsoft, which emphasizes a component-based approach to software development. In its third version, C# is still evolving, and this book guides you on a journey of learning how that evolution helps you accomplish more in your software engineering endeavors.
C# is one of several languages of the .NET (pronounced "dot net") platform, which includes a runtime engine called the Common Language Runtime (CLR) and a huge class library. The runtime is a virtual machine that manages code and provides several other services. The class library includes literally thousands of reusable objects and supports several user interface technologies for both desktop and Web Application development.
C# is evolving as a programming language. It began life as an object-oriented, component-based language but now is growing into areas that were once considered the domain of functional programming languages. Throughout this book, you'll see examples of objects and components being used as building blocks for applications. You'll also see many examples that include Language Integrated Query (LINQ), which is a declarative way to query data sources, whether the data source is in the form of objects, relational,
Just as C# (and the .NET platform) has evolved, so has this book. C# Unleashed began as a language-centric learning guide and reference for applying the C# programming language. The audience was varied because C# was new and developers from all types of backgrounds were programming with it. All the applications compiled on the command line, and all you needed was the .NET Framework SDK and an editor to do everything.
At its essence, the same concepts driving the first version of this book made it into this version. For example, you don't need to already know .NET before getting started. If you've programmed with any programming language, C# 3.0 Unleashed should be an easy on-ramp for you. This book contains a few command-line examples, especially in the beginning, because I believe that using the command line is a skill that is still necessary and useful. However, I quickly move to the Visual Studio 2008 (VS2008) Integrated Development Environment (IDE) for the largest share of the rest of the book. You aren't required to use VS2008, however; I show you right away how to build your applications without it, and Appendix A, "Compiling Programs," is a guide to command-line options with examples (just like the first version of C# Unleashed). However, VS2008 is an incredible tool for increasing productivity, and I provide tips throughout this book for cranking out algorithms with code-focused RAD.
In addition to coverage of VS2008, I've included several new chapters for the newest technologies, such as Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), and AJAX. If you like the cutting edge, there are chapters on the ADO.NET Entity Framework and ADO.NET Data Services. Speaking of data, I've added an entire part of this book with multiple chapters on working with data.
Since July 2000, when I cracked open the first public pre-beta release of .NET, I've been hooked, with C# as my language of choice. I've made a good living and found my C# skills in demand, even in a difficult economy. Most of all, I've gained an enormous amount of experience in both teaching, as a formal course instructor, and as a developer, delivering value to customers with an awesome toolset. I hope that all the gotchas, tips, and doses of reality that I've encountered and shared in this book will help you learn and thrive as I have.
Why This Book Is for You
If you've developed software in any other computer programming language, you will be able to understand the contents of this book with no trouble. You already know how to make logical decisions and construct iterative code. You also understand variables and basic number systems such as hexadecimal. Novices may want to start with something at the introductory level, such as Sams Teach Yourself C# in 21 Days. Honestly, ambitious beginners could do well with this book if they're motivated.
This is a book written for any programmer who wants to learn C# and .NET. It's basic enough for you to see every aspect of C# that's possible, yet it's sufficiently advanced to provide insight into the modern enterprise-level tasks you deal with every day.
Organization and Goals
C# 3.0 Unleashed is divided into eight parts. To promote learning from the beginning, it starts with the simpler material and those items strictly related to the C# language itself. Later, the book moves into other C#-related areas, showing how to use data, user interface technologies, web services, and other useful .NET technologies.
Part 1 is the beginning, covering basic C# language syntax and other essentials. Chapter 1 starts you off by discussing the .NET platform. This is an important chapter because you need to know the environment that you are building applications for. It permeates everything else you do as a C# developer and should be a place you return to on occasion to remind yourself of the essential ingredients of being a successful C# developer. In Chapter 2, you learn how to build a simple C# application using both the command line and VS2008. It is just the beginning of much VS2008 coverage to come. Chapter 3 is another essential milestone for success in developing .NET applications with C#, learning the type system. Chapters 4 and 5 show you how to work with strings and arrays, respectively. By the time you reach Chapter 7, you'll have enough skills necessary to write a simple application and encounter bugs. So, I hope you find my tips on using the VS2008 debugger helpful before moving on to more complexity with object-oriented programming in Part 2.
Part 2 covers object and component programming in C#. In the first version of C# Unleashed, I dedicated an entire chapter to basic object-oriented programming concepts. What changed in C# 3.0 Unleashed is that I weaved some of those concepts into other chapters. This way, developers who already know object-oriented programming don't have to skip over an entire chapter, but those who don't aren't completely left out. Mostly, I concentrate on how C# implements object-oriented programming, explaining those nuances that are of interest to existing object-oriented programmers and necessary for any C# developer.
Part 3 teaches you some of the more advanced features of C#. With an understanding of objects from Part 2, you learn about object lifetimewhen objects are first instantiated and when they are cleaned up from memory. An entire body of knowledge builds upon earlier chapters, leading to where you need to be to understand .NET memory management, the Garbage Collector, what it means for you as a C# developer, and mostly, what you can do to ensure that your objects and the resources they work with are properly managed.
Part 4 gives you five chapters of data. Feedback from the first version of this book indicated that you wanted more. So, now you can learn about LINQ to Objects, LINQ to SQL, ADO.NET, LINQ to DataSet,
Part 5 demonstrates how to use various desktop user interface technologies. You have choices, console applications, which were beefed up in .NET 2.0, Windows Forms, and WPF. By the way, if you are interested in Silverlight, you'll want to read the WPF chapter first because both technologies use XAML, the same layout, and the same control set. Not only does it help me bring more information to you on these new technologies, but it also should be comforting that what you learn with one technology is useful with another, expanding your skill set as a .NET developer.
Part 7 brings you in touch with various communications technologies. In a connected world, these chapters teach you how to use essential tools. You learn how to use TCP/IP, HTTP, and FTP, and send email using .NET Framework libraries. The remoting chapter is still there, as is the web services chapter. However, an additional chapter covers the new WCF web services.
Part 8 covers topics in architecture and design. Many programmers learn C# and all the topics discussed previously and then find their own way to build applications with what they've learned. If they find an effective way to build applications, then that is positive. However, it's common for people to want to know what the best way is for putting together all of these objects, components, and services to build a usable application. I don't have all the answers because architecture and design is a big topic, and there are as many opinions about it as there are questions. However, I've taken a quick foray into the subject, showing you some of the techniques that have worked for me. You learn how C# and .NET support common design patterns and make it easy for you to use these patterns. I show you how to build an n-layered application and describe a couple more ways that you can take what I've presented and use it in your own way. I also show you how to use a couple .NET tools, including the Class Designer, and introduce you to Windows Workflow (WF), which has a graphical design surface for building applications graphically.
Part 9 is a grab bag of technologies that could be important to your development, depending on what you want to do. For example, multithreading is something that most programmers will do on occasion. However, multithreading is a skill that most programmers will need as multiprocessing and multicore CPUs become more common, meaning that I added more multiprocessing/multithreaded information in this version of the book. Depending on where you are in the world, localization and globalization could be very important, so I explain the essentials of resources and satellite assemblies for localization purposes. There is still a lot of legacy code that people need to communicate with, depending on the needs of the project you are working on. To help out, the chapter on Interop covers P/Invoke for interoperating with Win32 DLLs and COM Interop for working with COM. There's also some information on working with COM+. For those of you who like a solution out of the box, I explain how to use the .NET trace facilities for instrumenting and logging. There's also a section on how to use existing performance counters and how to instrument your own code with a custom performance counter for diagnostics through the Windows Performance Monitor.
Part 10 helps you with your ultimate goal: deploying code. This is a series of quick chapters to help you build setup programs and deploy desktop or web applications. Before that, I give you some more information about assemblies and what they are made of. The Security chapter will help you learn how the .NET Code Access Security (CAS) system works. Along the way, I throw in several tips to ensure that your deployment endeavors go more smoothly than if you would have had to do it alone.
That's what this book is all about. I wish you luck in learning C# and hope that you find C# 3.0 Unleashed a helpful learning tool and useful reference.
© Copyright Pearson Education. All rights reserved.