Synopses & Reviews
When you have a question about C# 5.0 or the .NET CLR, this bestselling guide has precisely the answers you need. Uniquely organized around concepts and use cases, this updated fifth edition features a reorganized section on concurrency, threading, and parallel programming—including in-depth coverage of C# 5.0s new asynchronous functions.
Shaped by more than 20 expert reviewers, including Microsofts Eric Lippert, Stephen Toub, Chris Burrows, and Jon Skeet, this book has all you need to stay on track with C# 5.0. Its widely known as the definitive reference on the language.
- Get up to speed on C# language basics, including syntax, types, and variables
- Explore advanced topics such as unsafe code and type variance
- Dig deep into LINQ via three chapters dedicated to the topic
- Learn about code contracts, dynamic programming, and parallel programming
- Work with .NET features, including reflection, assemblies, memory management, security, I/O, XML, collections, networking, and native interoperability
"C# 5.0 in a Nutshell is one of the few books I keep on my desk as a quick reference."
—Scott Guthrie, Microsoft
"Whether youre a novice programmer or an expert who wants to improve your knowledge of modern asynchronous programming techniques, this book has the information you need to get the job done in C#."
—Eric Lippert, Microsoft
When you have a question about how to use C# 5.0 or the .NET CLR, this highly acclaimed bestseller has precisely the answers you need. Uniquely organized around concepts and use cases, this fifth edition include in-depth cover of concurrency and asynchrony new to C# 5.0 as well as continued coverage of parallel programming, code contracts, dynamic programming, security and COM interoperability. You'll also find updated information on language enhancements such as Caller Info Attributes, ReadOnlyDictionary, Web Sockets, and the new HttpClient class. This handy book has all you need to stay on track with C# 5.0.
- Get up to speed on C# language basics, including syntax, types, and variables
- Explore advanced topics such as unsafe code and preprocessor directives
- Learn C# 5.0 features such as concurrency and asynchrony
- Work with .NET 4.5's rich set of features for parallel programming, code contracts, and the code security model
- Understand .NET topics, including XML, collections, I/O and networking, memory management, reflection, attributes, security, and native interoperability
About the Author
Joseph Albahari is author of C# 3.0 in a Nutshell, LINQ Pocket Reference, and C# 3.0 Pocket Reference. He has been developing large-scale enterprise applications on .NET and other platforms for more than 15 years, and is author of LINQPad - the popular utility for querying databases in LINQ.
Joseph is currently a freelance consultant.
Joseph's Home Page
Ben Albahari is the founder of Take On It. He was a Program Manager at Microsoft for 5 years, where he worked on several projects, including the .NET Compact Framework and ADO.NET.
He was the cofounder of Genamics, a provider of tools for C# and J++ programmers, as well as software for DNA and protein sequence analysis. He is a co-author of C# Essentials, the first C# book from O'Reilly, and of previous editions of C# in a Nutshell.
Table of Contents
Preface; Intended Audience; How This Book Is Organized; What You Need to Use This Book; Conventions Used in This Book; Using Code Examples; Safari® Books Online; How to Contact Us; Acknowledgments; Chapter 1: Introducing C# and the .NET Framework; 1.1 Object Orientation; 1.2 Type Safety; 1.3 Memory Management; 1.4 Platform Support; 1.5 C#'s Relationship with the CLR; 1.6 The CLR and .NET Framework; 1.7 C# and Windows Runtime; 1.8 What's New in C# 5.0; 1.9 What's New in C# 4.0; 1.10 What's New in C# 3.0; Chapter 2: C# Language Basics; 2.1 A First C# Program; 2.2 Syntax; 2.3 Type Basics; 2.4 Numeric Types; 2.5 Boolean Type and Operators; 2.6 Strings and Characters; 2.7 Arrays; 2.8 Variables and Parameters; 2.9 Expressions and Operators; 2.10 Statements; 2.11 Namespaces; Chapter 3: Creating Types in C#; 3.1 Classes; 3.2 Inheritance; 3.3 The object Type; 3.4 Structs; 3.5 Access Modifiers; 3.6 Interfaces; 3.7 Enums; 3.8 Nested Types; 3.9 Generics; Chapter 4: Advanced C#; 4.1 Delegates; 4.2 Events; 4.3 Lambda Expressions; 4.4 Anonymous Methods; 4.5 try Statements and Exceptions; 4.6 Enumeration and Iterators; 4.7 Nullable Types; 4.8 Operator Overloading; 4.9 Extension Methods; 4.10 Anonymous Types; 4.11 Dynamic Binding; 4.12 Attributes; 4.13 Caller Info Attributes (C# 5); 4.14 Unsafe Code and Pointers; 4.15 Preprocessor Directives; 4.16 XML Documentation; Chapter 5: Framework Overview; 5.1 The CLR and Core Framework; 5.2 Applied Technologies; Chapter 6: Framework Fundamentals; 6.1 String and Text Handling; 6.2 Dates and Times; 6.3 Dates and Time Zones; 6.4 Formatting and Parsing; 6.5 Standard Format Strings and Parsing Flags; 6.6 Other Conversion Mechanisms; 6.7 Globalization; 6.8 Working with Numbers; 6.9 Enums; 6.10 Tuples; 6.11 The Guid Struct; 6.12 Equality Comparison; 6.13 Order Comparison; 6.14 Utility Classes; Chapter 7: Collections; 7.1 Enumeration; 7.2 The ICollection and IList Interfaces; 7.3 The Array Class; 7.4 Lists, Queues, Stacks, and Sets; 7.5 Dictionaries; 7.6 Customizable Collections and Proxies; 7.7 Plugging in Equality and Order; Chapter 8: LINQ Queries; 8.1 Getting Started; 8.2 Fluent Syntax; 8.3 Query Expressions; 8.4 Deferred Execution; 8.5 Subqueries; 8.6 Composition Strategies; 8.7 Projection Strategies; 8.8 Interpreted Queries; 8.9 LINQ to SQL and Entity Framework; 8.10 Building Query Expressions; Chapter 9: LINQ Operators; 9.1 Overview; 9.2 Filtering; 9.3 Projecting; 9.4 Joining; 9.5 Ordering; 9.6 Grouping; 9.7 Set Operators; 9.8 Conversion Methods; 9.9 Element Operators; 9.10 Aggregation Methods; 9.11 Quantifiers; 9.12 Generation Methods; Chapter 10: LINQ to XML; 10.1 Architectural Overview; 10.2 X-DOM Overview; 10.3 Instantiating an X-DOM; 10.4 Navigating and Querying; 10.5 Updating an X-DOM; 10.6 Working with Values; 10.7 Documents and Declarations; 10.8 Names and Namespaces; 10.9 Annotations; 10.10 Projecting into an X-DOM; Chapter 11: Other XML Technologies; 11.1 XmlReader; 11.2 XmlWriter; 11.3 Patterns for Using XmlReader/XmlWriter; 11.4 XmlDocument; 11.5 XPath; 11.6 XSD and Schema Validation; 11.7 XSLT; Chapter 12: Disposal and Garbage Collection; 12.1 IDisposable, Dispose, and Close; 12.2 Automatic Garbage Collection; 12.3 Finalizers; 12.4 How the Garbage Collector Works; 12.5 Managed Memory Leaks; 12.6 Weak References; Chapter 13: Diagnostics and Code Contracts; 13.1 Conditional Compilation; 13.2 Debug and Trace Classes; 13.3 Code Contracts Overview; 13.4 Preconditions; 13.5 Postconditions; 13.6 Assertions and Object Invariants; 13.7 Contracts on Interfaces and Abstract Methods; 13.8 Dealing with Contract Failure; 13.9 Selectively Enforcing Contracts; 13.10 Static Contract Checking; 13.11 Debugger Integration; 13.12 Processes and Process Threads; 13.13 StackTrace and StackFrame; 13.14 Windows Event Logs; 13.15 Performance Counters; 13.16 The Stopwatch Class; Chapter 14: Concurrency and Asynchrony; 14.1 Introduction; 14.2 Threading; 14.3 Tasks; 14.4 Principles of Asynchrony; 14.5 Asynchronous Functions in C# 5.0; 14.6 Asynchronous Patterns; 14.7 Obsolete Patterns; Chapter 15: Streams and I/O; 15.1 Stream Architecture; 15.2 Using Streams; 15.3 Stream Adapters; 15.4 Compression Streams; 15.5 Working with Zip Files; 15.6 File and Directory Operations; 15.7 File I/O in Windows Runtime; 15.8 Memory-Mapped Files; 15.9 Isolated Storage; Chapter 16: Networking; 16.1 Network Architecture; 16.2 Addresses and Ports; 16.3 URIs; 16.4 Client-Side Classes; 16.5 Working with HTTP; 16.6 Writing an HTTP Server; 16.7 Using FTP; 16.8 Using DNS; 16.9 Sending Mail with SmtpClient; 16.10 Using TCP; 16.11 Receiving POP3 Mail with TCP; 16.12 TCP in Windows Runtime; Chapter 17: Serialization; 17.1 Serialization Concepts; 17.2 The Data Contract Serializer; 17.3 Data Contracts and Collections; 17.4 Extending Data Contracts; 17.5 The Binary Serializer; 17.6 Binary Serialization Attributes; 17.7 Binary Serialization with ISerializable; 17.8 XML Serialization; Chapter 18: Assemblies; 18.1 What's in an Assembly; 18.2 Strong Names and Assembly Signing; 18.3 Assembly Names; 18.4 Authenticode Signing; 18.5 The Global Assembly Cache; 18.6 Resources and Satellite Assemblies; 18.7 Resolving and Loading Assemblies; 18.8 Deploying Assemblies Outside the Base Folder; 18.9 Packing a Single-File Executable; 18.10 Working with Unreferenced Assemblies; Chapter 19: Reflection and Metadata; 19.1 Reflecting and Activating Types; 19.2 Reflecting and Invoking Members; 19.3 Reflecting Assemblies; 19.4 Working with Attributes; 19.5 Dynamic Code Generation; 19.6 Emitting Assemblies and Types; 19.7 Emitting Type Members; 19.8 Emitting Generic Methods and Types; 19.9 Awkward Emission Targets; 19.10 Parsing IL; Chapter 20: Dynamic Programming; 20.1 The Dynamic Language Runtime; 20.2 Numeric Type Unification; 20.3 Dynamic Member Overload Resolution; 20.4 Implementing Dynamic Objects; 20.5 Interoperating with Dynamic Languages; Chapter 21: Security; 21.1 Permissions; 21.2 Code Access Security (CAS); 21.3 Allowing Partially Trusted Callers; 21.4 The Transparency Model; 21.5 Sandboxing Another Assembly; 21.6 Operating System Security; 21.7 Identity and Role Security; 21.8 Cryptography Overview; 21.9 Windows Data Protection; 21.10 Hashing; 21.11 Symmetric Encryption; 21.12 Public Key Encryption and Signing; Chapter 22: Advanced Threading; 22.1 Synchronization Overview; 22.2 Exclusive Locking; 22.3 Locking and Thread Safety; 22.4 Non-Exclusive Locking; 22.5 Signaling with Event Wait Handles; 22.6 The Barrier Class; 22.7 Lazy Initialization; 22.8 Thread-Local Storage; 22.9 Interrupt and Abort; 22.10 Suspend and Resume; 22.11 Timers; Chapter 23: Parallel Programming; 23.1 Why PFX?; 23.2 PLINQ; 23.3 The Parallel Class; 23.4 Task Parallelism; 23.5 Working with AggregateException; 23.6 Concurrent Collections; 23.7 BlockingCollection; Chapter 24: Application Domains; 24.1 Application Domain Architecture; 24.2 Creating and Destroying Application Domains; 24.3 Using Multiple Application Domains; 24.4 Using DoCallBack; 24.5 Monitoring Application Domains; 24.6 Domains and Threads; 24.7 Sharing Data Between Domains; Chapter 25: Native and COM Interoperability; 25.1 Calling into Native DLLs; 25.2 Type Marshaling; 25.3 Callbacks from Unmanaged Code; 25.4 Simulating a C Union; 25.5 Shared Memory; 25.6 Mapping a Struct to Unmanaged Memory; 25.7 COM Interoperability; 25.8 Calling a COM Component from C#; 25.9 Embedding Interop Types; 25.10 Primary Interop Assemblies; 25.11 Exposing C# Objects to COM; Chapter 26: Regular Expressions; 26.1 Regular Expression Basics; 26.2 Quantifiers; 26.3 Zero-Width Assertions; 26.4 Groups; 26.5 Replacing and Splitting Text; 26.6 Cookbook Regular Expressions; 26.7 Regular Expressions Language Reference; Colophon;