Home Page Icon
Home Page
Table of Contents for
Index
Close
Index
by Jeffrey Richter
CLR via C#, Fourth Edition
CLR via C#, Fourth Edition
Dedication
Foreword
Introduction
Who This Book Is For
Acknowledgments
Errata & Book Support
We Want to Hear from You
Stay in Touch
I. CLR Basics
1. The CLR’s Execution Model
Compiling Source Code into Managed Modules
Combining Managed Modules into Assemblies
Loading the Common Language Runtime
Executing Your Assembly’s Code
IL and Verification
Unsafe Code
The Native Code Generator Tool: NGen.exe
The Framework Class Library
The Common Type System
The Common Language Specification
Interoperability with Unmanaged Code
2. Building, Packaging, Deploying, and Administering Applications and Types
.NET Framework Deployment Goals
Building Types into a Module
Response Files
A Brief Look at Metadata
Combining Modules to Form an Assembly
Adding Assemblies to a Project by Using the Visual Studio IDE
Using the Assembly Linker
Adding Resource Files to an Assembly
Assembly Version Resource Information
Version Numbers
Culture
Simple Application Deployment (Privately Deployed Assemblies)
Simple Administrative Control (Configuration)
3. Shared Assemblies and Strongly Named Assemblies
Two Kinds of Assemblies, Two Kinds of Deployment
Giving an Assembly a Strong Name
The Global Assembly Cache
Building an Assembly That References a Strongly Named Assembly
Strongly Named Assemblies Are Tamper-Resistant
Delayed Signing
Privately Deploying Strongly Named Assemblies
How the Runtime Resolves Type References
Advanced Administrative Control (Configuration)
Publisher Policy Control
II. Designing Types
4. Type Fundamentals
All Types Are Derived from System.Object
Casting Between Types
Casting with the C# is and as Operators
Namespaces and Assemblies
How Things Relate at Run Time
5. Primitive, Reference, and Value Types
Programming Language Primitive Types
Checked and Unchecked Primitive Type Operations
Reference Types and Value Types
Boxing and Unboxing Value Types
Changing Fields in a Boxed Value Type by Using Interfaces (and Why You Shouldn’t Do This)
Object Equality and Identity
Object Hash Codes
The dynamic Primitive Type
6. Type and Member Basics
The Different Kinds of Type Members
Type Visibility
Friend Assemblies
Member Accessibility
Static Classes
Partial Classes, Structures, and Interfaces
Components, Polymorphism, and Versioning
How the CLR Calls Virtual Methods, Properties, and Events
Using Type Visibility and Member Accessibility Intelligently
Dealing with Virtual Methods When Versioning Types
7. Constants and Fields
Constants
Fields
8. Methods
Instance Constructors and Classes (Reference Types)
Instance Constructors and Structures (Value Types)
Type Constructors
Operator Overload Methods
Operators and Programming Language Interoperability
Conversion Operator Methods
Extension Methods
Rules and Guidelines
Extending Various Types with Extension Methods
The Extension Attribute
Partial Methods
Rules and Guidelines
9. Parameters
Optional and Named Arguments
Rules and Guidelines
The DefaultParameterValue and Optional Attributes
Implicitly Typed Local Variables
Passing Parameters by Reference to a Method
Passing a Variable Number of Arguments to a Method
Parameter and Return Type Guidelines
Const-ness
10. Properties
Parameterless Properties
Automatically Implemented Properties
Defining Properties Intelligently
Object and Collection Initializers
Anonymous Types
The System.Tuple Type
Parameterful Properties
The Performance of Calling Property Accessor Methods
Property Accessor Accessibility
Generic Property Accessor Methods
11. Events
Designing a Type That Exposes an Event
Step #1: Define a type that will hold any additional information that should be sent to receivers of the event notification
Step #2: Define the event member
Step #3: Define a method responsible for raising the event to notify registered objects that the event has occurred
Step #4: Define a method that translates the input into the desired event
How the Compiler Implements an Event
Designing a Type That Listens for an Event
Explicitly Implementing an Event
12. Generics
Generics in the Framework Class Library
Generics Infrastructure
Open and Closed Types
Generic Types and Inheritance
Generic Type Identity
Code Explosion
Generic Interfaces
Generic Delegates
Delegate and Interface Contra-variant and Covariant Generic Type Arguments
Generic Methods
Generic Methods and Type Inference
Generics and Other Members
Verifiability and Constraints
Primary Constraints
Secondary Constraints
Constructor Constraints
Other Verifiability Issues
Casting a Generic Type Variable
Setting a Generic Type Variable to a Default Value
Comparing a Generic Type Variable with null
Comparing Two Generic Type Variables with Each Other
Using Generic Type Variables as Operands
13. Interfaces
Class and Interface Inheritance
Defining an Interface
Inheriting an Interface
More About Calling Interface Methods
Implicit and Explicit Interface Method Implementations (What’s Happening Behind the Scenes)
Generic Interfaces
Generics and Interface Constraints
Implementing Multiple Interfaces That Have the Same Method Name and Signature
Improving Compile-Time Type Safety with Explicit Interface Method Implementations
Be Careful with Explicit Interface Method Implementations
Design: Base Class or Interface?
III. Essential Types
14. Chars, Strings, and Working with Text
Characters
The System.String Type
Constructing Strings
Strings Are Immutable
Comparing Strings
String Interning
String Pooling
Examining a String’s Characters and Text Elements
Other String Operations
Constructing a String Efficiently
Constructing a StringBuilder Object
StringBuilder Members
Obtaining a String Representation of an Object: ToString
Specific Formats and Cultures
Formatting Multiple Objects into a Single String
Providing Your Own Custom Formatter
Parsing a String to Obtain an Object: Parse
Encodings: Converting Between Characters and Bytes
Encoding and Decoding Streams of Characters and Bytes
Base-64 String Encoding and Decoding
Secure Strings
15. Enumerated Types and Bit Flags
Enumerated Types
Bit Flags
Adding Methods to Enumerated Types
16. Arrays
Initializing Array Elements
Casting Arrays
All Arrays Are Implicitly Derived from System.Array
All Arrays Implicitly Implement IEnumerable, ICollection, and IList
Passing and Returning Arrays
Creating Non-Zero Lower Bound Arrays
Array Internals
Unsafe Array Access and Fixed-Size Array
17. Delegates
A First Look at Delegates
Using Delegates to Call Back Static Methods
Using Delegates to Call Back Instance Methods
Demystifying Delegates
Using Delegates to Call Back Many Methods (Chaining)
C#’s Support for Delegate Chains
Having More Control over Delegate Chain Invocation
Enough with the Delegate Definitions Already (Generic Delegates)
C#’s Syntactical Sugar for Delegates
Syntactical Shortcut #1: No Need to Construct a Delegate Object
Syntactical Shortcut #2: No Need to Define a Callback Method (Lambda Expressions)
Syntactical Shortcut #3: No Need to Wrap Local Variables in a Class Manually to Pass Them to a Callback Method
Delegates and Reflection
18. Custom Attributes
Using Custom Attributes
Defining Your Own Attribute Class
Attribute Constructor and Field/Property Data Types
Detecting the Use of a Custom Attribute
Matching Two Attribute Instances Against Each Other
Detecting the Use of a Custom Attribute Without Creating Attribute-Derived Objects
Conditional Attribute Classes
19. Nullable Value Types
C#’s Support for Nullable Value Types
C#’s Null-Coalescing Operator
The CLR Has Special Support for Nullable Value Types
Boxing Nullable Value Types
Unboxing Nullable Value Types
Calling GetType via a Nullable Value Type
Calling Interface Methods via a Nullable Value Type
IV. Core Facilities
20. Exceptions and State Management
Defining “Exception”
Exception-Handling Mechanics
The try Block
The catch Block
The finally Block
The System.Exception Class
FCL-Defined Exception Classes
Throwing an Exception
Defining Your Own Exception Class
Trading Reliability for Productivity
Guidelines and Best Practices
Use finally Blocks Liberally
Don’t Catch Everything
Recovering Gracefully from an Exception
Backing Out of a Partially Completed Operation When an Unrecoverable Exception Occurs—Maintaining State
Hiding an Implementation Detail to Maintain a “Contract”
Unhandled Exceptions
Debugging Exceptions
Exception-Handling Performance Considerations
Constrained Execution Regions (CERs)
Code Contracts
21. The Managed Heap and Garbage Collection
Managed Heap Basics
Allocating Resources from the Managed Heap
The Garbage Collection Algorithm
Garbage Collections and Debugging
Generations: Improving Performance
Garbage Collection Triggers
Large Objects
Garbage Collection Modes
Forcing Garbage Collections
Monitoring Your Application’s Memory Usage
Working with Types Requiring Special Cleanup
Using a Type That Wraps a Native Resource
An Interesting Dependency Issue
Other GC Features for Use with Native Resources
Finalization Internals
Monitoring and Controlling the Lifetime of Objects Manually
22. CLR Hosting and AppDomains
CLR Hosting
AppDomains
Accessing Objects Across AppDomain Boundaries
Demo #1: Cross-AppDomain Communication Using Marshal-by-Reference
Demo #2: Cross-AppDomain Communication Using Marshal-by-Value
Demo #3: Cross-AppDomain Communication Using Non-Marshalable Types
AppDomain Unloading
AppDomain Monitoring
AppDomain First-Chance Exception Notifications
How Hosts Use AppDomains
Executable Applications
Microsoft Silverlight Rich Internet Applications
Microsoft ASP.NET and XML Web Services Applications
Microsoft SQL Server
Your Own Imagination
Advanced Host Control
Managing the CLR by Using Managed Code
Writing a Robust Host Application
How a Host Gets Its Thread Back
23. Assembly Loading and Reflection
Assembly Loading
Using Reflection to Build a Dynamically Extensible Application
Reflection Performance
Discovering Types Defined in an Assembly
What Exactly Is a Type Object?
Building a Hierarchy of Exception-Derived Types
Constructing an Instance of a Type
Designing an Application That Supports Add-Ins
Using Reflection to Discover a Type’s Members
Discovering a Type’s Members
Invoking a Type’s Members
Using Binding Handles to Reduce Your Process’s Memory Consumption
24. Runtime Serialization
Serialization/Deserialization Quick Start
Making a Type Serializable
Controlling Serialization and Deserialization
How Formatters Serialize Type Instances
Controlling the Serialized/Deserialized Data
How to Define a Type That Implements ISerializable When the Base Type Doesn’t Implement This Interface
Streaming Contexts
Serializing a Type As a Different Type and Deserializing an Object As a Different Object
Serialization Surrogates
Surrogate Selector Chains
Overriding the Assembly and/or Type When Deserializing an Object
25. Interoperating with WinRT Components
CLR Projections and WinRT Component Type System Rules
WinRT Type System Core Concepts
Framework Projections
Calling Asynchronous WinRT APIs from .NET Code
Interoperating Between WinRT Streams and .NET Streams
Passing Blocks of Data Between the CLR and WinRT
Defining WinRT Components in C#
V. Threading
26. Thread Basics
Why Does Windows Support Threads?
Thread Overhead
Stop the Madness
CPU Trends
CLR Threads and Windows Threads
Using a Dedicated Thread to Perform an Asynchronous Compute-Bound Operation
Reasons to Use Threads
Thread Scheduling and Priorities
Foreground Threads vs. Background Threads
What Now?
27. Compute-Bound Asynchronous Operations
Introducing the CLR’s Thread Pool
Performing a Simple Compute-Bound Operation
Execution Contexts
Cooperative Cancellation and Timeout
Tasks
Waiting for a Task to Complete and Getting Its Result
Canceling a Task
Starting a New Task Automatically When Another Task Completes
A Task May Start Child Tasks
Inside a Task
Task Factories
Task Schedulers
Parallel’s Static For, ForEach, and Invoke Methods
Parallel Language Integrated Query
Performing a Periodic Compute-Bound Operation
So Many Timers, So Little Time
How the Thread Pool Manages Its Threads
Setting Thread Pool Limits
How Worker Threads Are Managed
28. I/O-Bound Asynchronous Operations
How Windows Performs I/O Operations
C#’s Asynchronous Functions
How the Compiler Transforms an Async Function into a State Machine
Async Function Extensibility
Async Functions and Event Handlers
Async Functions in the Framework Class Library
Async Functions and Exception Handling
Other Async Function Features
Applications and Their Threading Models
Implementing a Server Asynchronously
Canceling I/O Operations
Some I/O Operations Must Be Done Synchronously
FileStream-Specific Issues
I/O Request Priorities
29. Primitive Thread Synchronization Constructs
Class Libraries and Thread Safety
Primitive User-Mode and Kernel-Mode Constructs
User-Mode Constructs
Volatile Constructs
C#’s Support for Volatile Fields
Interlocked Constructs
Implementing a Simple Spin Lock
The Interlocked Anything Pattern
Kernel-Mode Constructs
Event Constructs
Semaphore Constructs
Mutex Constructs
30. Hybrid Thread Synchronization Constructs
A Simple Hybrid Lock
Spinning, Thread Ownership, and Recursion
Hybrid Constructs in the Framework Class Library
The ManualResetEventSlim and SemaphoreSlim Classes
The Monitor Class and Sync Blocks
The ReaderWriterLockSlim Class
The OneManyLock Class
The CountdownEvent Class
The Barrier Class
Thread Synchronization Construct Summary
The Famous Double-Check Locking Technique
The Condition Variable Pattern
Asynchronous Synchronization
The Concurrent Collection Classes
Index
About the Author
Copyright
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
Index
Next
Next Chapter
Index
D
data collections, LINQ queries on,
Parallel Language Integrated Query
data encapsulation,
Parameterless Properties
data types, for custom attribute classes,
Attribute Constructor and Field/Property Data Types
date formatting,
Specific Formats and Cultures
dates and times, in WinRT,
WinRT Type System Core Concepts
DateTime,
Parsing a String to Obtain an Object: Parse
,
WinRT Type System Core Concepts
structure,
WinRT Type System Core Concepts
type,
Parsing a String to Obtain an Object: Parse
DateTimeFormatInfo type,
Specific Formats and Cultures
DateTimeOffset structure,
WinRT Type System Core Concepts
debuggers,
Thread Overhead
,
How Windows Performs I/O Operations
asynchronous I/O operations and,
How Windows Performs I/O Operations
threads and,
Thread Overhead
debugging,
Unhandled Exceptions
,
Garbage Collections and Debugging
and garbage collections,
Garbage Collections and Debugging
exceptions,
Unhandled Exceptions
decimal type,
Programming Language Primitive Types
,
Checked and Unchecked Primitive Type Operations
declaring delegates,
A First Look at Delegates
declaring methods, for variable number of arguments,
Passing Parameters by Reference to a Method
declaring properties,
Automatically Implemented Properties
,
Anonymous Types
in anonymous types,
Anonymous Types
Decoder class,
Encoding and Decoding Streams of Characters and Bytes
Decoding,
Encoding and Decoding Streams of Characters and Bytes
,
Encoding and Decoding Streams of Characters and Bytes
bytes,
Encoding and Decoding Streams of Characters and Bytes
strings,
Encoding and Decoding Streams of Characters and Bytes
Decrement method,
A Simple Hybrid Lock
dedicated threads,
Using a Dedicated Thread to Perform an Asynchronous Compute-Bound Operation
default AppDomain,
AppDomains
DefaultMember attribute,
Parameterful Properties
DefaultParameterValue attribute,
The DefaultParameterValue and Optional Attributes
defining,
Using Type Visibility and Member Accessibility Intelligently
,
Instance Constructors and Classes (Reference Types)
,
Parameterless Properties
classes,
Using Type Visibility and Member Accessibility Intelligently
fields, without initialization,
Instance Constructors and Classes (Reference Types)
properties,
Parameterless Properties
definition tables in metadata,
A Brief Look at Metadata
Delay method,
Performing a Periodic Compute-Bound Operation
delayed signing,
Delayed Signing
Delegate class,
Demystifying Delegates
delegate fields,
How the Compiler Implements an Event
delegate types,
Extending Various Types with Extension Methods
,
Making a Type Serializable
,
WinRT Type System Core Concepts
extension methods for,
Extending Various Types with Extension Methods
serializing,
Making a Type Serializable
WinRT,
WinRT Type System Core Concepts
delegates,
The Extension Attribute
,
Events
,
Generic Interfaces
,
Delegate and Interface Contra-variant and Covariant Generic Type Arguments
,
Delegate and Interface Contra-variant and Covariant Generic Type Arguments
,
Using Delegates to Call Back Static Methods
,
Using Delegates to Call Back Static Methods
,
Using Delegates to Call Back Instance Methods
,
Demystifying Delegates
,
Demystifying Delegates
,
Demystifying Delegates
,
Using Delegates to Call Back Many Methods (Chaining)
,
Using Delegates to Call Back Many Methods (Chaining)
,
Using Delegates to Call Back Many Methods (Chaining)
,
Using Delegates to Call Back Many Methods (Chaining)
,
C#’s Support for Delegate Chains
,
Enough with the Delegate Definitions Already (Generic Delegates)
,
Enough with the Delegate Definitions Already (Generic Delegates)
,
Enough with the Delegate Definitions Already (Generic Delegates)
,
C#’s Syntactical Sugar for Delegates
,
C#’s Syntactical Sugar for Delegates
,
Syntactical Shortcut #2: No Need to Define a Callback Method (Lambda Expressions)
,
Delegates and Reflection
callback method, invoking,
Demystifying Delegates
calling back instance methods,
Using Delegates to Call Back Instance Methods
calling back static methods with,
Using Delegates to Call Back Static Methods
calling private members with,
Using Delegates to Call Back Static Methods
chaining,
Using Delegates to Call Back Many Methods (Chaining)
chaining, C# support for,
C#’s Support for Delegate Chains
chaining, result variable and,
Using Delegates to Call Back Many Methods (Chaining)
class defined by,
Demystifying Delegates
,
Demystifying Delegates
contravariant type parameters,
Delegate and Interface Contra-variant and Covariant Generic Type Arguments
covariant type parameters,
Delegate and Interface Contra-variant and Covariant Generic Type Arguments
defining,
Enough with the Delegate Definitions Already (Generic Delegates)
definitions for,
Enough with the Delegate Definitions Already (Generic Delegates)
extension methods and,
The Extension Attribute
garbage collection,
Using Delegates to Call Back Many Methods (Chaining)
generic,
Generic Interfaces
,
Enough with the Delegate Definitions Already (Generic Delegates)
reflection and,
Delegates and Reflection
removing from chains,
Using Delegates to Call Back Many Methods (Chaining)
syntax,
C#’s Syntactical Sugar for Delegates
syntax shortcuts for,
C#’s Syntactical Sugar for Delegates
,
Syntactical Shortcut #2: No Need to Define a Callback Method (Lambda Expressions)
Delete method, exceptions thrown by,
Using a Type That Wraps a Native Resource
delete operator,
All Types Are Derived from System.Object
DeleteAsync method,
Async Functions in the Framework Class Library
deploying assemblies,
Culture
,
Privately Deploying Strongly Named Assemblies
privately,
Privately Deploying Strongly Named Assemblies
derived class,
Be Careful with Explicit Interface Method Implementations
derived types, preconditions and,
Code Contracts
deserialization,
Serialization/Deserialization Quick Start
,
Serialization/Deserialization Quick Start
,
Serialization/Deserialization Quick Start
,
Serialization/Deserialization Quick Start
,
Controlling Serialization and Deserialization
,
Controlling Serialization and Deserialization
,
How Formatters Serialize Type Instances
,
Controlling the Serialized/Deserialized Data
,
Controlling the Serialized/Deserialized Data
,
Serializing a Type As a Different Type and Deserializing an Object As a Different Object
,
Serializing a Type As a Different Type and Deserializing an Object As a Different Object
,
Serialization Surrogates
,
Overriding the Assembly and/or Type When Deserializing an Object
,
Overriding the Assembly and/or Type When Deserializing an Object
controlling,
Controlling Serialization and Deserialization
controlling data,
Controlling the Serialized/Deserialized Data
formatter consistency,
Serialization/Deserialization Quick Start
into object graphs,
Serialization/Deserialization Quick Start
matching serialization method,
Controlling the Serialized/Deserialized Data
of application state,
Serialization/Deserialization Quick Start
of collection objects,
Controlling Serialization and Deserialization
of objects, as different objects,
Serializing a Type As a Different Type and Deserializing an Object As a Different Object
of singleton types,
Serializing a Type As a Different Type and Deserializing an Object As a Different Object
of type instances,
How Formatters Serialize Type Instances
overriding assembly/type,
Overriding the Assembly and/or Type When Deserializing an Object
quick start for,
Serialization/Deserialization Quick Start
surrogates for,
Serialization Surrogates
type bindings,
Overriding the Assembly and/or Type When Deserializing an Object
Deserialize method,
Serializing a Type As a Different Type and Deserializing an Object As a Different Object
DeserializeFromStream method,
Serialization/Deserialization Quick Start
deserializing objects,
Instance Constructors and Classes (Reference Types)
diagnostics namespace,
Thread Scheduling and Priorities
dictionary type, serialization,
Controlling the Serialized/Deserialized Data
direct memory accesses,
Array Internals
DisableOptimizations flag,
Garbage Collections and Debugging
disambiguating types,
Namespaces and Assemblies
DispatcherTimer classes,
So Many Timers, So Little Time
DispatcherUnhandledException event,
Unhandled Exceptions
Display method,
Generic Methods and Type Inference
Dispose method,
Designing a Type That Listens for an Event
,
Secure Strings
,
Garbage Collections and Debugging
,
Using a Type That Wraps a Native Resource
,
Using a Type That Wraps a Native Resource
,
Using a Type That Wraps a Native Resource
,
An Interesting Dependency Issue
,
WinRT Type System Core Concepts
,
Cooperative Cancellation and Timeout
,
Inside a Task
calling explicitly,
An Interesting Dependency Issue
in finally block,
Using a Type That Wraps a Native Resource
native resource cleanup and,
Using a Type That Wraps a Native Resource
on Task objects,
Inside a Task
distributed applications, unhandled exceptions in,
Unhandled Exceptions
DllMain method,
Thread Overhead
DLLs,
Thread Overhead
,
Thread Overhead
performance issues and,
Thread Overhead
thread-attach and thread-detach notifications,
Thread Overhead
double type,
Programming Language Primitive Types
double-check locking,
The Famous Double-Check Locking Technique
downloading assemblies from web,
Assembly Loading
DumpBin.exe,
Loading the Common Language Runtime
dynamic expressions, as object types,
The dynamic Primitive Type
dynamic keyword,
Implicitly Typed Local Variables
dynamic type,
Programming Language Primitive Types
,
The dynamic Primitive Type
,
The dynamic Primitive Type
vs. var keyword,
The dynamic Primitive Type
dynamically extensible applications,
Assembly Loading and Reflection
DynamicAttribute method,
The dynamic Primitive Type
DynamicInvoke method,
Delegates and Reflection
dynamification,
The dynamic Primitive Type
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