Chapter 15 Enumerated Types and Bit Flags 361Enumerated Types....................................................................................... 361
Bit Flags........................................................................................................... 367
Adding Methods to Enumerated Types..................................................... 371
Chapter 16 Arrays 373
Initializing Array Elements........................................................................... 376
Casting Arrays............................................................................................... 378
All Arrays Are Implicitly Derived from System.Array........................... 380
All Arrays Implicitly Implement IEnumerable, ICollection,
and IList................................................................................................. 381
Passing and Returning Arrays.................................................................... 382
Creating Non-Zero Lower Bound Arrays.................................................. 383
Array Internals................................................................................................ 384
Unsafe Array Access and Fixed-Size Array.............................................. 388
Chapter 17 Delegates 391
A First Look at Delegates............................................................................. 391
Using Delegates to Call Back Static Methods.......................................... 394
Using Delegates to Call Back Instance Methods..................................... 395
Contents xiii
Demystifying Delegates............................................................................. 396
Using Delegates to Call Back Many Methods (Chaining)...................... 400
C#’s Support for Delegate Chains.................................................. 404
Having More Control over Delegate Chain Invocation................ 404
Enough with the Delegate Definitions Already (Generic Delegates).. 407
C#’s Syntactical Sugar for Delegates........................................................ 408
Syntactical Shortcut #1: No Need to Construct a
Delegate Object.................................................................................. 409
Syntactical Shortcut #2: No Need to Define a Callback Method
(Lambda Expressions)...................................................................... 410
Syntactical Shortcut #3: No Need to Wrap Local Variables
in a Class Manually to Pass Them to a Callback Method........... 413
Delegates and Reflection............................................................................ 416
Chapter 18 Custom Attributes 421
Using Custom Attributes.............................................................................. 421
Defining Your Own Attribute Class............................................................. 425
Attribute Constructor and Field/Property Data Types............................... 428
Detecting the Use of a Custom Attribute................................................... 430
Matching Two Attribute Instances Against Each Other........................... 434
Detecting the Use of a Custom Attribute Without Creating
Attribute-Derived Objects........................................................................ 437
Conditional Attribute Classes...................................................................... 440
Chapter 19 Nullable Value Types 441
C#’s Support for Nullable Value Types..................................................... 443
C#’s Null-Coalescing Operator................................................................... 446
The CLR Has Special Support for Nullable Value Types...................... 447
Boxing Nullable Value Types........................................................... 447
Unboxing Nullable Value Types...................................................... 448
Calling GetType via a Nullable Value Type.................................. 448
Calling Interface Methods via a Nullable Value Type.................. 448
Xiv Contents
PART IV CORE FACILITIES
Date: 2016-03-03; view: 804
|