Author: Bart De Smet
Pub Date: 2013
Size: 41 Mb
C# 5.0 Unleashed is for anyone who wants to learn the C# programming language in depth, understanding how language features truly work. While giving you those insights, you learn where and how to use the features to design various kinds of software. This book not only teaches the language’s capabilities, it also looks behind the scenes to build a solid foundation to aid you in understanding the .NET platform as a whole.
Bart De Smet offers exceptional insight into the features of both the language and Microsoft’s broader framework. He doesn’t just cover the “what” and “how” of effective C# programming: He explains the “why,” so you can consistently choose the right language and platform features, maximizing your efficiency and effectiveness.
The early chapters introduce the .NET platform, the tooling ecosystem, and the C# programming language, followed by in-depth coverage of the C# programming language itself, with immediate application of language features. The last chapters give an overview of the .NET Framework libraries about which every good developer on the platform should know.
- Understand the .NET platform: its language support, libraries, tools, and more
- Learn where C# fits, how it has evolved, and where it’s headed
- Master essential language features including expressions, operators, types, objects, and methods
- Efficiently manage exceptions and resources
- Write more effective C# object-oriented code
- Make the most of generics, collections, delegates, reflection, and other advanced language features
- Use LINQ to express queries for any form of data
- Master dynamic programming techniques built on .NET’s Dynamic Language Runtime (DLR)
- Work with namespaces, assemblies, and application domains
- Write more efficient code using threading, synchronization, and advanced parallel programming techniques
- Leverage the Base Class Library (BCL) to quickly perform many common tasks
- Instrument, diagnose, test, and troubleshoot your C# code
- Understand how to use the new C# 5.0 asynchronous programming features
- Leverage interoperability with Windows Runtime to build Windows 8 applications
Here, the card object is checked against various types, and when a match is found data is extracted from it and bound to local variables. Pattern matching doesn’t operate only on regular objects; it can also be used to match over different types such as lists (extracting the head element and tail list) or tuples (extracting the elements at the different positions in the tuple).
It’s not clear whether C# will ever get a full-fledged pattern matching operator. But it would definitely seem to be the better feature compared to simple type switching and may provide more value. In the meantime, if you’re designing an API that needs to be friendly toward type switching and the use of virtual methods doesn’t give you what you want, you have some workarounds.
For example, the expression tree APIs in System.Linq.Expressions—which we explore during our discussion of reflection in Chapter 21, “Reflection”—provide a tree-based object model for expressions and statements. It’s a convenient way to represent code as data so that code can be inspected at runtime (for example, for interpretation, optimization, and translation). It’s common for consumers of such an API to have to switch on types corresponding to nodes in the tree. For example, a + operation will be represented as a BinaryExpression, whereas a ! operation is done using a UnaryExpression. Not to mention other types of expressions like method calls and such.
Good layers of abstraction supported by language features such as code patterns (for example, foreach loops, using blocks, query syntax), object orientation, namespaces, and so on provide a win-win situation in this jungle of libraries. From the library writer’s point of view, an API can be given, by obeying good design principles, a natural feeling for users in various languages. At the same time, users’ skill sets can be reused to target all those libraries. Language design principles, such as static typing, together with runtime facilities, such as rich metadata support, tend to aid users in exploring APIs. A good example of tooling features leveraging this can be found in IntelliSense and the Object Browser (which should really be called Type Browser).
Doing justice to all the framework libraries just by reviewing them in a shallow manner is nearly impossible, so refer to specialized titles for deep coverage of things such as user interface (UI) programming (for example, using Windows Presentation Foundation [WPF] or Extensible Application Markup Language [XAML] for Windows Store apps), targeting the Web (for example, using ASP.NET and Silverlight), communication and services (for example, using WCF), and so forth. Often, the number of auxiliary concepts introduced by those technology pillars