Home Page Icon
Home Page
Table of Contents for
About the Author
Close
About the Author
by Trey Nash
Accelerated C# 2010
Copyright
About the Author
About the Technical Reviewer
Acknowledgments
Preface
About This Book
1. C# Preview
1.1. Differences Between C# and C++
1.1.1. C#
1.1.2. C++
1.1.3. CLR Garbage Collection
1.2. Example of a C# Program
1.3. Overview of Features Added in C# 2.0
1.4. Overview of Features Added in C# 3.0
1.5. Overview of New C# 4.0 Features
1.6. Summary
2. C# and the CLR
2.1. The JIT Compiler in the CLR
2.2. Assemblies and the Assembly Loader
2.2.1. Minimizing the Working Set of the Application
2.2.2. Naming Assemblies
2.2.3. Loading Assemblies
2.3. Metadata
2.4. Cross-Language Compatibility
2.5. Summary
3. C# Syntax Overview
3.1. C# Is a Strongly Typed Language
3.2. Expressions
3.3. Statements and Expressions
3.4. Types and Variables
3.4.1. Value Types
3.4.1.1. Enumerations
3.4.1.2. Flags Enumerations
3.4.2. Reference Types
3.4.3. Default Variable Initialization
3.4.4. Implicitly Typed Local Variables
3.4.5. Type Conversion
3.4.5.1. Array Covariance
3.4.5.2. Boxing Conversion
3.4.6. as and is Operators
3.4.7. Generics
3.5. Namespaces
3.5.1. Defining Namespaces
3.5.2. Using Namespaces
3.6. Control Flow
3.6.1. if-else, while, do-while, and for
3.6.2. switch
3.6.3. foreach
3.6.4. break, continue, goto, return, and throw
3.7. Summary
4. Classes, Structs, and Objects
4.1. Class Definitions
4.1.1. Fields
4.1.2. Constructors
4.1.3. Methods
4.1.3.1. Static Methods
4.1.3.2. Instance Methods
4.1.4. Properties
4.1.4.1. Declaring Properties
4.1.4.2. Accessors
4.1.4.3. Read-Only and Write-Only Properties
4.1.4.4. Auto-Implemented Properties
4.1.5. Encapsulation
4.1.6. Accessibility
4.1.7. Interfaces
4.1.8. Inheritance
4.1.8.1. Accessibility of Members
4.1.8.2. Implicit Conversion and a Taste of Polymorphism
4.1.8.3. Member Hiding
4.1.8.4. The base Keyword
4.1.9. sealed Classes
4.1.10. abstract Classes
4.1.11. Nested Classes
4.1.12. Indexers
4.1.13. partial Classes
4.1.14. partial Methods
4.1.15. Static Classes
4.1.16. Reserved Member Names
4.1.16.1. Reserved Names for Properties
4.1.16.2. Reserved Names for Indexers
4.1.16.3. Reserved Names for Destructors
4.1.16.4. Reserved Names for Events
4.2. Value Type Definitions
4.2.1. Constructors
4.2.2. The Meaning of this
4.2.3. Finalizers
4.2.4. Interfaces
4.3. Anonymous Types
4.4. Object Initializers
4.5. Boxing and Unboxing
4.5.1. When Boxing Occurs
4.5.2. Efficiency and Confusion
4.6. System.Object
4.6.1. Equality and What It Means
4.6.2. The IComparable Interface
4.7. Creating Objects
4.7.1. The new Keyword
4.7.1.1. Using new with Value Types
4.7.1.2. Using new with Class Types
4.7.2. Field Initialization
4.7.3. Static (Class) Constructors
4.7.4. Instance Constructor and Creation Ordering
4.8. Destroying Objects
4.8.1. Finalizers
4.8.2. Deterministic Destruction
4.8.3. Exception Handling
4.9. Disposable Objects
4.9.1. The IDisposable Interface
4.9.2. The using Keyword
4.10. Method Parameter Types
4.10.1. Value Arguments
4.10.2. ref Arguments
4.10.3. out Parameters
4.10.4. param Arrays
4.10.5. Method Overloading
4.10.6. Optional Arguments
4.10.7. Named Arguments
4.11. Inheritance and Virtual Methods
4.11.1. Virtual and Abstract Methods
4.11.2. override and new Methods
4.11.3. sealed Methods
4.11.4. A Final Few Words on C# Virtual Methods
4.12. Inheritance, Containment, and Delegation
4.12.1. Choosing Between Interface and Class Inheritance
4.12.2. Delegation and Composition vs. Inheritance
4.13. Summary
5. Interfaces and Contracts
5.1. Interfaces Define Types
5.2. Defining Interfaces
5.2.1. What Can Be in an Interface?
5.2.2. Interface Inheritance and Member Hiding
5.3. Implementing Interfaces
5.3.1. Implicit Interface Implementation
5.3.2. Explicit Interface Implementation
5.3.3. Overriding Interface Implementations in Derived Classes
5.3.4. Beware of Side Effects of Value Types Implementing Interfaces
5.4. Interface Member Matching Rules
5.5. Explicit Interface Implementation with Value Types
5.6. Versioning Considerations
5.7. Contracts
5.7.1. Contracts Implemented with Classes
5.7.2. Interface Contracts
5.8. Choosing Between Interfaces and Classes
5.9. Summary
6. Overloading Operators
6.1. Just Because You Can Doesn't Mean You Should
6.2. Types and Formats of Overloaded Operators
6.3. Operators Shouldn't Mutate Their Operands
6.4. Does Parameter Order Matter?
6.5. Overloading the Addition Operator
6.6. Operators That Can Be Overloaded
6.6.1. Comparison Operators
6.6.2. Conversion Operators
6.6.3. Boolean Operators
6.7. Summary
7. Exception Handling and Exception Safety
7.1. How the CLR Treats Exceptions
7.2. Mechanics of Handling Exceptions in C#
7.2.1. Throwing Exceptions
7.2.2. Changes with Unhandled Exceptions Starting with .NET 2.0
7.2.3. Syntax Overview of the try, catch, and finally Statements
7.2.4. Rethrowing Exceptions and Translating Exceptions
7.2.5. Exceptions Thrown in finally Blocks
7.2.6. Exceptions Thrown in Finalizers
7.2.7. Exceptions Thrown in Static Constructors
7.3. Who Should Handle Exceptions?
7.4. Avoid Using Exceptions to Control Flow
7.5. Achieving Exception Neutrality
7.5.1. Basic Structure of Exception-Neutral Code
7.5.2. Constrained Execution Regions
7.5.3. Critical Finalizers and SafeHandle
7.6. Creating Custom Exception Classes
7.7. Working with Allocated Resources and Exceptions
7.8. Providing Rollback Behavior
7.9. Summary
8. Working with Strings
8.1. String Overview
8.2. String Literals
8.3. Format Specifiers and Globalization
8.3.1. Object.ToString, IFormattable, and CultureInfo
8.3.2. Creating and Registering Custom CultureInfo Types
8.3.3. Format Strings
8.3.4. Console.WriteLine and String.Format
8.3.5. Examples of String Formatting in Custom Types
8.3.6. ICustomFormatter
8.3.7. Comparing Strings
8.4. Working with Strings from Outside Sources
8.5. StringBuilder
8.6. Searching Strings with Regular Expressions
8.6.1. Searching with Regular Expressions
8.6.2. Searching and Grouping
8.6.3. Replacing Text with Regex
8.6.4. Regex Creation Options
8.7. Summary
9. Arrays, Collection Types, and Iterators
9.1. Introduction to Arrays
9.1.1. Implicitly Typed Arrays
9.1.2. Type Convertibility and Covariance
9.1.3. Sortability and Searchability
9.1.4. Synchronization
9.1.5. Vectors vs. Arrays
9.2. Multidimensional Rectangular Arrays
9.3. Multidimensional Jagged Arrays
9.4. Collection Types
9.4.1. Comparing ICollection<T> with ICollection
9.4.2. Collection Synchronization
9.4.3. Lists
9.4.4. Dictionaries
9.4.5. Sets
9.4.6. System.Collections.ObjectModel
9.4.7. Efficiency
9.5. IEnumerable<T>, IEnumerator<T>, IEnumerable, and IEnumerator
9.5.1. Types That Produce Collections
9.6. Iterators
9.6.1. Forward, Reverse, and Bidirectional Iterators
9.7. Collection Initializers
9.8. Summary
10. Delegates, Anonymous Functions, and Events
10.1. Overview of Delegates
10.2. Delegate Creation and Use
10.2.1. Single Delegate
10.2.2. Delegate Chaining
10.2.3. Iterating Through Delegate Chains
10.2.4. Unbound (Open Instance) Delegates
10.3. Events
10.4. Anonymous Methods
10.4.1. Captured Variables and Closures
10.4.2. Beware the Captured Variable Surprise
10.4.3. Anonymous Methods as Delegate Parameter Binders
10.5. The Strategy Pattern
10.6. Summary
11. Generics
11.1. Difference Between Generics and C++ Templates
11.2. Efficiency and Type Safety of Generics
11.3. Generic Type Definitions and Constructed Types
11.3.1. Generic Classes and Structs
11.3.2. Generic Interfaces
11.3.3. Generic Methods
11.3.4. Generic Delegates
11.3.5. Generic Type Conversion
11.3.6. Default Value Expression
11.3.7. Nullable Types
11.3.8. Constructed Types Control Accessibility
11.3.9. Generics and Inheritance
11.4. Constraints
11.4.1. Constraints on Nonclass Types
11.5. Co- and Contravariance
11.5.1. Covariance
11.5.2. Contravariance
11.5.3. Invariance
11.5.4. Variance and Delegates
11.6. Generic System Collections
11.7. Generic System Interfaces
11.8. Select Problems and Solutions
11.8.1. Conversion and Operators within Generic Types
11.8.2. Creating Constructed Types Dynamically
11.9. Summary
12. Threading in C#
12.1. Threading in C# and .NET
12.1.1. Starting Threads
12.1.1.1. Passing Data to New Threads
12.1.1.2. Using ParameterizedThreadStart
12.1.2. The IOU Pattern and Asynchronous Method Calls
12.1.3. States of a Thread
12.1.4. Terminating Threads
12.1.5. Halting Threads and Waking Sleeping Threads
12.1.6. Waiting for a Thread to Exit
12.1.7. Foreground and Background Threads
12.1.8. Thread-Local Storage
12.1.9. How Unmanaged Threads and COM Apartments Fit In
12.2. Synchronizing Work Between Threads
12.2.1. Lightweight Synchronization with the Interlocked Class
12.2.2. SpinLock Class
12.2.3. Monitor Class
12.2.3.1. Beware of Boxing
12.2.3.2. Pulse and Wait
12.2.4. Locking Objects
12.2.4.1. ReaderWriterLock
12.2.4.2. ReaderWriterLockSlim
12.2.4.3. Mutex
12.2.5. Semaphore
12.2.6. Events
12.2.7. Win32 Synchronization Objects and WaitHandle
12.3. Using ThreadPool
12.3.1. Asynchronous Method Calls
12.3.2. Timers
12.4. Concurrent Programming
12.4.1. Task Class
12.4.2. Parallel Class
12.4.3. Easy Entry to the Thread Pool
12.5. Thread-Safe Collection Classes
12.6. Summary
13. In Search of C# Canonical Forms
13.1. Reference Type Canonical Forms
13.1.1. Default to sealed Classes
13.1.2. Use the Non-Virtual Interface (NVI) Pattern
13.1.3. Is the Object Cloneable?
13.1.4. Is the Object Disposable?
13.1.5. Does the Object Need a Finalizer?
13.1.6. What Does Equality Mean for This Object?
13.1.6.1. Reference Types and Identity Equality
13.1.6.2. Value Equality
13.1.6.3. Overriding Object.Equals for Reference Types
13.1.7. If You Override Equals, Override GetHashCode Too
13.1.8. Does the Object Support Ordering?
13.1.9. Is the Object Formattable?
13.1.10. Is the Object Convertible?
13.1.11. Prefer Type Safety at All Times
13.1.12. Using Immutable Reference Types
13.2. Value Type Canonical Forms
13.2.1. Override Equals for Better Performance
13.2.2. Do Values of This Type Support Any Interfaces?
13.2.3. Implement Type-Safe Forms of Interface Members and Derived Methods
13.3. Summary
13.3.1. Checklist for Reference Types
13.3.2. Checklist for Value Types
14. Extension Methods
14.1. Introduction to Extension Methods
14.1.1. How Does the Compiler Find Extension Methods?
14.1.2. Under the Covers
14.1.3. Code Readability versus Code Understandability
14.2. Recommendations for Use
14.2.1. Consider Extension Methods Over Inheritance
14.2.2. Isolate Extension Methods in Separate Namespace
14.2.3. Changing a Type's Contract Can Break Extension Methods
14.3. Transforms
14.4. Operation Chaining
14.5. Custom Iterators
14.5.1. Borrowing from Functional Programming
14.6. The Visitor Pattern
14.7. Summary
15. Lambda Expressions
15.1. Introduction to Lambda Expressions
15.1.1. Lambda Expressions and Closures
15.1.1.1. Closures in C# 1.0
15.1.1.2. Closures in C# 2.0
15.1.2. Lambda Statements
15.2. Expression Trees
15.2.1. Operating on Expressions
15.2.2. Functions as Data
15.3. Useful Applications of Lambda Expressions
15.3.1. Iterators and Generators Revisited
15.3.2. More on Closures (Variable Capture) and Memoization
15.3.3. Currying
15.3.4. Anonymous Recursion
15.4. Summary
16. LINQ: Language Integrated Query
16.1. A Bridge to Data
16.1.1. Query Expressions
16.1.2. Extension Methods and Lambda Expressions Revisited
16.2. Standard Query Operators
16.3. C# Query Keywords
16.3.1. The from Clause and Range Variables
16.3.2. The join Clause
16.3.3. The where Clause and Filters
16.3.4. The orderby Clause
16.3.5. The select Clause and Projection
16.3.6. The let Clause
16.3.7. The group Clause
16.3.8. The into Clause and Continuations
16.4. The Virtues of Being Lazy
16.4.1. C# Iterators Foster Laziness
16.4.2. Subverting Laziness
16.4.3. Executing Queries Immediately
16.4.4. Expression Trees Revisited
16.5. Techniques from Functional Programming
16.5.1. Custom Standard Query Operators and Lazy Evaluation
16.5.2. Replacing foreach Statements
16.6. Summary
17. Dynamic Types
17.1. What does dynamic Mean?
17.2. How Does dynamic Work?
17.2.1. The Great Unification
17.2.2. Call Sites
17.2.3. Objects with Custom Dynamic Behavior
17.2.4. Efficiency
17.2.5. Boxing with Dynamic
17.3. Dynamic Conversions
17.3.1. Implicit Dynamic Expressions Conversion
17.4. Dynamic Overload Resolution
17.5. Dynamic Inheritance
17.5.1. You Cannot Derive from dynamic
17.5.2. You Cannot Implement dynamic Interfaces
17.5.3. You Can Derive From Dynamic Base Types
17.6. Duck Typing in C#
17.7. Limitations of dynamic Types
17.8. ExpandoObject: Creating Objects Dynamically
17.9. Summary
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Copyright
Next
Next Chapter
About the Technical Reviewer
About the Author
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset