- Animation
- Application design
- ASP.NET
- C#, .NET 3.5
- Controls
- Data access
- Effects
- Expression Blend
- Expression Design
- Game development
- Graphics
- Javascript and AJAX
- Math and Physics
- Media streaming
- Multimedia
- Security
- Silverlight
- Styling
- UI Design
- VB.NET
- Video
- Visual Studio
- WCF
- WPF
- XAML

BlueForest Networks

Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition
Publisher: Apress - November 12, 2007 ISBN-10: 1590598849, ISBN-13: 9781590598849
Author: Andrew Troelsen
1370 pages
The last version, .NET 3.0, was more of an augmentative release, essentially providing three new APIs: Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF). As you would expect, coverage of the "W's" has been expanded a great deal in this version of the book from the previous Special Edition text.
Unlike .NET 3.0, .NET 3.5 provides dozens of new C# language features and .NET APIs. This edition of the book will walk you through all of this new material using the same readable approach as was found in previous editions. Rest assured, you'll find detailed coverage of Language Integrated Query (LINQ), the C# 2008 language changes (automatic properties, extension methods, anonymous types, etc.) and the numerous bells and whistles of Visual Studio 2008. What you will learn
- Everything you need to know - get up to speed with C# 2008 quickly and efficiently.
- Discover all the new .NET 3.5 features -- Language Integrated Query, anonymous types, extension methods, automatic properties, and more.
- Get a professional foothold -- targeted to appeal to experienced software professionals, this book gives you the facts you need the way you need to see them.
- A rock-solid foundation - focuses on everything you need to be a successful .NET 3.5 programmer, not just the new features. Get comfortable with all the core aspects of the platform -- including assemblies, remoting, Windows Forms, Web Forms, ADO.NET, XML web services, and much more.
If you're checking out this book for the first time, understand that it targets experienced software professionals and/or students of computer science (so please don't expect three chapters devoted to "for" loops). The mission of this text is to provide you with a rock-solid foundation to the C# 2008 programming language and the core aspects of the .NET platform (OOP, assemblies, file IO, Windows Forms/WPF, ASP.NET, ADO.NET, WCF,WF, etc.). Once you digest the information presented in these 33 chapters, you'll be in a perfect position to apply this knowledge to your specific programming assignments, and you'll be well equipped to explore the .NET universe on your own terms. About the Apress Pro series
You have gotten the job; now you need to go hone your skills in these tough competitive times. Apress Pro Series books expand your skills and expertise in exactly the areas you need. Master the content of a Pro book and you will always be able to get the job done in a professional manner. Written by experts in their field, Pro Series books give you the hard-won solutions to problems you will face in your professional programming career.
The purpose of Part 1 is to acclimate you to the nature of the .NET platform and various development
tools (many of which are open source) used during the construction of .NET applications.
Along the way, you will also check out some basic details of the C# programming language and the
.NET type system.
Chapter 1: The Philosophy of .NET
This first chapter functions as the backbone for the remainder of the text. We begin by examining
the world of traditional Windows development and uncover the shortcomings with the previous
state of affairs. The primary goal of this chapter, however, is to acquaint you with a number of .NETcentric
building blocks, such as the common language runtime (CLR), Common Type System (CTS),
Common Language Specification (CLS), and base class libraries. Here, you will take an initial look at
the C# programming language and the .NET assembly format, and get an overview the platformindependent
nature of the .NET platform (Appendix B will examine this topic in greater detail).
Chapter 2: Building C# Applications
The goal of this chapter is to introduce you to the process of compiling C# source code files using
various tools and techniques. First, you will learn how to make use of the command-line compiler
(csc.exe) and C# response files. Over the remainder of the chapter, you will examine numerous
code editors and integrated development environments (IDEs), including TextPad, Notepad++,
SharpDevelop, Visual C# 2008 Express, and Visual Studio 2008. As well, you will be exposed to a
number of additional programming tools that any .NET developer should have in their back pocket.
Part 2: Core C# Programming Constructs
The topics presented in this part of the book are quite important, as they will be used regardless of
which type of .NET software you intend to develop (web applications, desktop GUI applications,
code libraries, Windows services, etc.). Here, you will come to understand the core constructs of the
C# language, including the details of object-oriented programming (OOP). As well, this part will
examine how to process runtime exceptions and dive into the details of .NET’s garbage collection
services.
Chapter 3: Core C# Programming Constructs, Part I
This chapter begins your formal investigation of the C# programming language. Here you will learn
about the role of the Main()method and numerous details regarding the intrinsic data types of the
.NET platform, including the manipulation of textual data using System.String and System.Text.
StringBuilder. You will also examine iteration and decision constructs, narrowing and widening
operations, and use of the unchecked keyword.
Chapter 4: Core C# Programming Constructs, Part II
This chapter completes your examination of the core aspects of C#, beginning with the construction
of overloaded type methods and defining parameters via the out, ref, and params keywords.
You will also learn how to create and manipulate arrays of data, define nullable data types (with the
? and ?? operators), and understand the distinction between value types (including enumerations
and custom structures) and reference types.
Chapter 5: Defining Encapsulated Class Types
This chapter begins your examination of object-oriented programming (OOP) using the C# programming
language. Once we qualify the pillars of OOP (encapsulation, inheritance, and
polymorphism), the remainder of this chapter will examine how to build robust class types using
constructors, properties, static members, constants, and read-only fields. We wrap up with an
examination of partial type definitions and C#’s XML code documentation syntax.
Chapter 6: Understanding Inheritance and Polymorphism
Here, you will examine the remaining pillars of OOP (inheritance and polymorphism), which allow
you to build families of related class types. During this time, you will examine the role of virtual
methods, abstract methods (and abstract base classes), and the nature of the polymorphic interface.
Last but not least, this chapter will explain the role of the supreme base class of the .NET platform,
System.Object.
Chapter 7: Understanding Structured Exception Handling
The point of this chapter is to discuss how to handle runtime anomalies in your code base through
the use of structured exception handling. Not only will you learn about the C# keywords that allow
you to handle such problems (try, catch, throw, and finally), but you will also come to understand
the distinction between application-level and system-level exceptions. In addition, this chapter
examines various tools within Visual Studio 2008 that allow you to debug the exceptions that have
escaped your view.
Chapter 8: Understanding Object Lifetime
The final chapter of this part examines how the CLR manages memory using the .NET garbage collector.
Here you will come to understand the role of application roots, object generations, and the
System.GC type. Once you understand the basics, the remainder of this chapter covers the topics of
disposable objects (via the IDisposable interface) and the finalization process (via the System.
Object.Finalize() method).
Part 3: Advanced C# Programming Constructs
This section of the book will deepen your understanding of the C# language, by examining a number
of more advanced (but very important) concepts. Here, you will complete your examination of
the .NET type system by examining interfaces and delegates. As well, you will learn about the role of
generics and the numerous new language features of C# 2008, and take an initial look at Language
Integrated Query (LINQ).
Chapter 9: Working with Interfaces
The material in this chapter builds upon your understanding of object-based development by
covering the topic of interface-based programming. Here, you will learn how to define types that
support multiple behaviors, how to discover these behaviors at runtime, and how to selectively hide
particular behaviors using explicit interface implementation. In addition to examining a number of
predefined .NET interface types, you will also learn how to make use of custom interfaces to build
an ad hoc event architecture.
Chapter 10: Collections and Generics
This chapter begins by examining the collection types of the System.Collections namespace, which
has been part of the .NET platform since its initial release. However, since the release of .NET 2.0,
the C# programming language offers support for generics. As you will see, generic programming
greatly enhances application performance and type safety. Not only will you explore various generic
types within the System.Collections.Generic namespace, but you will also learn how to build your
own generic methods and types (with and without constraints).
Chapter 11: Delegates, Events, and Lambdas
The purpose of Chapter 11 is to demystify the delegate type. Simply put, a .NET delegate is an object
that “points” to other methods in your application. Using this pattern, you are able to build systems
that allow multiple objects to engage in a two-way conversation. After you have examined the use of
.NET delegates, you will then be introduced to the C# event keyword, which is used to simplify the
manipulation of raw delegate programming. You wrap up by investigating the role of the C# 2008
lambda operator (=>) and exploring the connection between delegates, anonymous methods, and
lambda expressions.
Chapter 12: Indexers, Operators, and Pointers
This chapter deepens your understanding of the C# programming language by introducing a number
of advanced programming techniques. Here, you will learn how to overload operators and
create custom conversion routines (both implicit and explicit) for your types. As well, you will learn
how to build and interact with type indexers, and manipulate C-style pointers using an “unsafe”
code context.
Chapter 13: C# 2008 Language Features
With the release of .NET 3.5, the C# language has been enhanced to support a great number of new
programming constructs, many of which are used to enable the LINQ API (which you will begin to
examine in Chapter 14). Here, you will learn the role of implicit typing of local variables, partial
methods, automatic properties, extension methods, anonymous types, and object initialization
syntax.
Chapter 14: An Introduction to LINQ
This chapter will begin your examination of Language Integrated Query (LINQ), which could easily
be considered the most intriguing aspect of .NET 3.5. As you will see in this chapter, LINQ allows
you to build strongly typed query expressions, which can be applied to a number of LINQ targets to
manipulate “data” in the broadest sense of the word. Here, you will learn about LINQ to Objects,
which allows you to apply LINQ expressions to containers of data (arrays, collections, custom
types). This information will serve you well when we examine how to apply LINQ expressions to
relational databases (via LINQ to ADO) and XML documents (à la LINQ to XML) later in Chapter 24.
Part 4: Programming with .NET Assemblies
Part 4 dives into the details of the .NET assembly format. Not only will you learn how to deploy and
configure .NET code libraries, but you will also come to understand the internal composition of a
.NET binary image. This part also explains the role of .NET attributes and the construction of multithreaded
applications. Later chapters examine some fairly advanced topics such as object context,
CIL code, and dynamic assemblies.
Chapter 15: Introducing .NET Assemblies
From a very high level, assembly is the term used to describe a managed *.dll or *.exe binary file.
However, the true story of .NET assemblies is far richer than that. Here you will learn the distinction
between single-file and multifile assemblies, and how to build and deploy each entity. You’ll examine
how private and shared assemblies may be configured using XML-based *.config files and
publisher policy assemblies. Along the way, you will investigate the internal structure of the global
assembly cache (GAC) and the role of the .NET Framework configuration utility.
Chapter 16: Type Reflection, Late Binding, and Attribute-Based Programming
Chapter 16 continues our examination of .NET assemblies by checking out the process of runtime
type discovery via the System.Reflection namespace. Using these types, you are able to build applications
that can read an assembly’s metadata on the fly. You will learn how to dynamically load and
create types at runtime using late binding. The final topic of this chapter explores the role of .NET
attributes (both standard and custom). To illustrate the usefulness of each of these topics, the chapter
concludes with the construction of an extendable Windows Forms application.
Chapter 17: Processes, AppDomains, and Object Contexts
Now that you have a solid understanding of assemblies, this chapter dives deeper into the composition
of a loaded .NET executable. The goal of this chapter is to illustrate the relationship between
processes, application domains, and contextual boundaries. These topics provide the proper foundation
for the topic of the following chapter, where we examine the construction of multithreaded
applications.
Chapter 18: Building Multithreaded Applications
This chapter examines how to build multithreaded applications and illustrates a number of techniques
you can use to author thread-safe code. The chapter opens by revisiting the .NET delegate
type in order to understand a delegate’s intrinsic support for asynchronous method invocations.
Next, you will investigate the types within the System.Threading namespace. You will look at numerous
types (Thread, ThreadStart, etc.) that allow you to easily create additional threads of execution.
We wrap up by examining the BackgroundWorker type, which greatly simplifies the creation of
threads from within a desktop user interface.
Chapter 19: Understanding CIL and the Role of Dynamic Assemblies
The goal of the final chapter of this part is twofold. In the first half (more or less), you will examine
the syntax and semantics of CIL in much greater detail than in previous chapters. The remainder of
this chapter covers the role of the System.Reflection.Emit namespace. Using these types, you are
able to build software that is capable of generating .NET assemblies in memory at runtime. Formally
speaking, assemblies defined and executed in memory are termed dynamic assemblies.
Part 5: Introducing the .NET Base Class Libraries
By this point in the text, you have a solid handle on the C# language and the details of the .NET
assembly format. Part 5 leverages your newfound knowledge by exploring a number of commonly
used services found within the base class libraries, including file I/O and database access using
ADO.NET. This part also covers the construction of distributed applications using Windows Communication
Foundation (WCF) and workflow-enabled applications that make use of the Windows
Workflow Foundation (WF) API.
Chapter 20: File I/O and Isolated Storage
The System.IO namespace allows you to interact with a machine’s file and directory structure. Over
the course of this chapter, you will learn how to programmatically create (and destroy) a directory
system as well as move data into and out of various streams (file based, string based, memory
based, etc.). The latter part of this chapter examines the role of isolated storage, which allows you to
persist per-user data into a safe sandbox, regardless of the security settings of a target machine. To
understand certain aspects of the System.IO.IsolatedStorage API, you will also receive an overview
of Code Access Security (CAS).
Chapter 21: Introducing Object Serialization
This chapter examines the object serialization services of the .NET platform. Simply put, serialization
allows you to persist the state of an object (or a set of related objects) into a stream for later use.
Deserialization (as you might expect) is the process of plucking an object from the stream into
memory for consumption by your application. Once you understand the basics, you will then learn
how to customize the serialization process via the ISerializable interface and a set of .NET
attributes.
Chapter 22: ADO.NET Part I: The Connected Layer
In this first of two database-centric chapters, you will learn about the ADO.NET programming API.
Specifically, this chapter will introduce the role of .NET data providers and how to communicate
with a relational database using the connected layer of ADO.NET, represented by connection
objects, command objects, transaction objects, and data reader objects. Be aware that this chapter
will also walk you through the creation of a custom database and a data access library that will be
used throughout the remainder of this text.
Chapter 23: ADO.NET Part II: The Disconnected Layer
This chapter continues your study of database manipulation by examining the disconnected layer
of ADO.NET. Here, you will learn the role of the DataSet type, data adapter objects, and numerous
tools of Visual Studio 2008 that can greatly simplify the creation of data-driven applications. Along
the way, you will learn how to bind DataTable objects to user interface elements, such as the
GridView type of the Windows Forms API.
Chapter 24: Programming with the LINQ APIs
Chapter 14 introduced you to the LINQ programming model, specifically LINQ to Objects. Here,
you will deepen your understanding of Language Integrated Query by examining how to apply
LINQ queries to relational databases, DataSet objects, and XML documents. Along the way, you will
learn the role of data context objects, the sqlmetal.exe utility, and various LINQ-specific aspects of
Visual Studio 2008.
Chapter 25: Introducing Windows Communication Foundation
.NET 3.0 introduced a brand-new API, WCF, that allows you to build distributed applications,
regardless of their underlying plumbing, in a symmetrical manner. This chapter will expose you to
the construction of WCF services, hosts, and clients. As you will see, WCF services are extremely
flexible, in that clients and hosts can leverage XML-based configuration files to declaratively specify
addresses, bindings, and contracts.
Chapter 26: Introducing Windows Workflow Foundation
In addition to WCF, .NET 3.0 also introduced an API, WF, that allows you to define, execute, and
monitor workflows to model complex business processes. Here, you will learn the overall purpose
ofWindows Workflow Foundation, as well as the role of activities, workflow designers, the workflow
runtime engine, and the creation of workflow-enabled code libraries.
Part 6: Desktop User Interfaces
It is a common misconception for newcomers to the .NET platform to assume this framework is
only concerned with the construction of web-based user interfaces (which I suspect is due to the
term “.NET,” as this tends to conjure up the notion of the “Internet” and therefore “web programs”).
While it is true that .NET provides outstanding support for the construction of web applications,
this part of the book focuses on traditional desktop user interfaces using two GUI frameworks,
Windows Forms and Windows Presentation Foundation (WPF).
Chapter 27: Programming with Windows Forms
The original desktop GUI toolkit that shipped with the .NET platform is termed Windows Forms.
This chapter will walk you through the role of this UI framework, and illustrate how to build main
windows, dialog boxes, and menu systems. As well, you will understand the role of form inheritance
and see how to render 2D graphical data using the System.Drawing namespace. To illustrate these
topics using a cohesive example, we wrap up by building a (semicapable) painting application.
Chapter 28: Introducing Windows Presentation Foundation and XAML
.NET 3.0 introduced a brand-new GUI toolkit termed WPF. Essentially, WPF allows you to build
extremely interactive and media-rich front ends for desktop applications (and indirectly, web applications).
Unlike Windows Forms, this supercharged UI framework integrates a number of key
services (2D and 3D graphics, animations, rich documents, etc.) into a single unified object model.
In this chapter, you will begin your examination of WPF and the Extendable Application Markup
Language (XAML). Here, you will learn how to build WPF programs XAML-free, using nothing but
XAML, and a combination of each. We wrap up by building a custom XAML viewer, which will be
used during the remainder of the WPF-centric chapters.