Programming C# 5.0: Building Windows 8, Web, and Desktop Applications for the .NET 4.5 Framework
After a dozen years of incremental changes, C# has become one of the most versatile programming languages available. With this comprehensive guide, you’ll learn just how powerful the combination of C# 5.0 and .NET 4.5 can be. Author Ian Griffiths guides you through C# 5.0 fundamentals and teaches you techniques for building web and desktop applications, including Windows 8-style apps.
Completely rewritten for experienced programmers, this book provides many code examples to help you work with the nuts and bolts of C# code, such as generics, dynamic typing, and the new asynchronous programming features. You’ll also get up to speed on XAML, ASP.NET, LINQ, and other .NET tools.
- Discover how C# supports fundamental coding features such as classes, other custom types, collections, and error handling
- Understand the differences between dynamic and static typing in C#
- Query and process diverse data sources such as in-memory object models, databases, and XML documents with LINQ
- Use .NET’s multithreading features to exploit your computer’s parallel processing capabilities
- Learn how the new asynchronous language features can help improve application responsiveness and scalability
- Use XAML to create Windows 8-style, phone, and classic desktop applications
returns an instance of an anonymous type with the same member names and types in the same order. The C# compiler deems that these will in fact be the same type, which is important here, because Aggregate requires the lambda to accept and also return an instance of the accumulator type. If C# did not guarantee that the two expressions returning anonymous type instances in this example would return the exact same type, we could not depend on this code to compile correctly. Example 10-43 uses a
restrictions on the use of threads in the .NET Core profile.) TaskPoolScheduler uses the Task Parallel Library’s (TPL) thread pool. The TPL, described in Chapter 17, provides an efficient pool of threads that can reuse a single thread for multiple work items, amortizing the startup costs of creating the thread in the first place. ThreadPoolScheduler uses the CLR’s thread pool to run work. This is similar in concept to the TPL thread pool, but it’s a somewhat older piece of technology. (The TPL
connection with the old pre-.NET ASP, which was short for Active Server Pages, but ASP.NET covers such a broad range of features that it would make no sense to insist that this is what the ASP part means.) Although the term ASP.NET covers a fairly wide range of server-side web technologies, these all share a common infrastructure, whether you’re writing web user interfaces or web services. For example, ASP.NET supports hosting code inside Microsoft’s web server, Internet Information Services
can use a simple, readable name in C#, and then set the DllImport attribute’s EntryPoint field to a string containing the real name. COM-Style Return Values Some methods exposed by DLLs use COM’s conventions for return values. (These conventions are used by almost all methods in COM interfaces, but you will also see them in many of the Win32 APIs that support COM.) To be able to report errors, COM methods usually have a return type of HRESULT. This is just a 32-bit integer, but it
compiler would need to generate a method call. (Custom operators are just methods under the covers.) Or if the type in question turns out not to support addition, the compiler should generate an error. There are several possible outcomes, depending on the actual types involved. That would be fine if the types were known to the compiler, but it has to compile the code for generic types and methods without knowing which types will be used as arguments. You might argue that perhaps Microsoft could