Rough Cuts are manuscripts that are developed but not yet published, available through Safari. Rough Cuts provide you access to the very latest information on a given topic and offer you the opportunity to interact with the author to influence the final publication.
This is a working draft of a pre-release book. It is available before the published date as part of the Rough Cuts service.
Real Solutions for C# 4.0 Programmers
Need fast, robust, efficient code solutions for Microsoft C# 4.0? This book delivers exactly what you’re looking for. You’ll find more than 200 solutions, best-practice techniques, and tested code samples for everything from classes to exceptions, networking to XML, LINQ to Silverlight. Completely up-to-date, this book fully reflects major language enhancements introduced with the new C# 4.0 and .NET 4.0. When time is of the essence, turn here first: Get answers you can trust and code you can use, right now!
Beginning with the language essentials and moving on to solving common problems using the .NET Framework, C# 4.0 How-To addresses a wide range of general programming problems and algorithms. Along the way is clear, concise coverage of a broad spectrum of C# techniques that will help developers of all levels become more proficient with C# and the most popular .NET tools.
Fast, Reliable, and Easy to Use!
Introduction 1
Overview of C# 4.0 How-To 1
How-To Benefit from This Book 1
How-To Continue Expanding Your Knowledge 3
PART I: C# FUNDAMENTALS
Chapter 1 Type Fundamentals 7
Create a Class 8
Define Fields, Properties, and Methods 9
Define Static Members 10
Add a Constructor 11
Initialize Properties at Construction 12
Use const and readonly 13
Reuse Code in Multiple Constructors 14
Derive from a Class 14
Call a Base Class Constructor 15
Override a Base Class’s Method or Property 16
Create an Interface 19
Implement Interfaces 19
Create a Struct 21
Create an Anonymous Type 22
Prevent Instantiation with an Abstract Base Class 23
Interface or Abstract Base Class? 24
Chapter 2 Creating Versatile Types 27
Format a Type with ToString() 28
Make Types Equatable. 32
Make Types Hashable with GetHashCode() 34
Make Types Sortable 34
Give Types an Index 36
Notify Clients when Changes Happen 38
Overload Appropriate Operators 39
Convert One Type to Another 40
Prevent Inheritance 41
Allow Value Type to Be Null 42
Chapter 3 General Coding 45
Declare Variables 46
Defer Type Checking to Runtime (Dynamic Types) 47
Use Dynamic Typing to Simplify COM Interop 49
Declare Arrays 50
Create Multidimensional Arrays 50
Alias a Namespace 51
Use the Conditional Operator (?:) 52
Use the Null-Coalescing Operator (??) 53
Add Methods to Existing Types with Extension Methods 54
Call Methods with Default Parameters 55
Call Methods with Named Parameters 56