Microsoft unveiled the .NET Framework in 2000, and in the decade that followed, it became an extremely popular choice for developing software for Windows. While .NET supports many programming languages, it is most strongly associated with the language designed specifically for the platform: C#.
C# has grown considerably since its launch. Each new version enabled new programming techniquesC# 2.0 added generics and enhanced functional programming capabilities, then integrated query features and yet more powerful functional capabilities arrived in C# 3.0, and now C# 4.0 adds new dynamic language capabilities.
The .NET Framework has grown with the language. Back in .NET 1.0, the class libraries offered relatively patchy coverage of the underlying Windows capabilities. Moreover, the library features that were unique to .NET, rather than being wrappers for something else, were relatively modest. Now, as well as more comprehensive platform coverage we have a GUI framework (WPF), much stronger database capabilities, powerful support for concurrent execution, and an extensive set of communication services (WCF), to name just a few of the available features. And the features that have been there since version 1.0, such as web support (ASP.NET), have been fleshed out substantially.
.NET is no longer limited to running just on Windows. Some people recognized its potential for platform independence early on, but for years, Microsoft supported C# just on Windows, leaving open source projects to offer the only way to run C# on other systems. But in 2008, the release of Silverlight 2 saw C# code running with Microsofts full support on non-Windows platforms such as the Mac for the first time.
The C# language has come a long way since 2000, in both reach and size. Our goal with Programming C# 4.0 is to show how to use C#.
How This Book Is Organized
The book begins by looking at the details of the C# language that you will use in everyday programming. We then look at the most common parts of the .NET Framework class library that you will also use very regularly. Next, we move into some more specialized areas of the framework. Finally, we look at some of the application frameworks for building Windows and web applications in .NET.
This chapter talks about the nature of C# and its relationship with the .NET Framework.
In this chapter, we show the core elements of C# codethe steps required to get up and running, and fundamental features such as variables, flow control, loops, and methods.
C# supports object-oriented programming, and this chapter describes the language features dedicated to these techniques.
This chapter continues the discussion from the preceding chapter, illustrating how C# supports inheritance, interfaces, and related concepts.
C# isnt limited to object-oriented programmingit also supports some very powerful functional programming idioms. This chapter shows how these can sometimes be more flexible and also simpler than OO techniques.
All programs encounter failures, whether due to programming errors, unexpected input, network failures, or a host of other eventualities. This chapter shows the options for detecting and responding robustly to errors.
This chapter shows the tools C# offers for representing simple collections of information .
Its not enough merely to be able to represent collections, so this chapter shows how you can use the integrated query features in C# to process your collections of data.
This chapter shows some of the more specialized classes for working with collections in particular ways.
Text is a particularly important data type for most applications, so this chapter shows how text is represented, and how you can format data into textual form.
This chapter shows how to store information on disk and read it back in, and how to perform other filesystem operations. It also shows how some of the abstractions used when working with files can be applied in other scenarios.
This chapter shows the classes offered by the .NET Framework for processing XML, and how these can work in conjunction with the LINQ features in C#.
In this chapter, we look at the various techniques for communicating over a network .
This chapter shows how to access a database from C#.
In this chapter, we show how to compile code into libraries for reuse, and how programs made up from multiple components work.
Many programs need to deal with concurrency, and this chapter shows the tools and techniques available.
C# has the ability to inspect the structure of code, which makes it easier to automate certain kinds of tasks. This chapter shows the API for doing this, and how you can extend the structural information through attributes.
One of the new features in C# 4.0 is support for dynamic binding. This is particularly useful in certain interop scenarios, as we discuss in this chapter.
Sometimes its necessary for C# code to communicate with components not designed to be used from .NET. This chapter shows how to do this with both COM components and Win32-style DLLs.
WPF and Silverlight offer very similar programming models for building user interfaces. This chapter shows how to use that model from C#.
This chapter shows how to use ASP.NET, the part of the .NET Framework designed for building web applications.
This chapter shows how to use Windows Forms, which is a wrapper around the classic Windows user interface mechanisms. While it is less flexible than WPF, it can offer an easier way to integrate with old components such as ActiveX controls.