NOTE: Page references marked with an n are footnotes
!
logical negation operator, 118–119
!=
, <
, <=
, ==
, >=
relational operators, 386
&&
, ||
, ^
logical Boolean operators, 116–118, 122–126
with flag enums, 365
()
(cast/conversion) operators, 61–64,
custom conversion operators, 391–393
%=
, *=
, /=
, +=
, -=
(compound assignment) operators, 97
overloading compound assignment operators, 387–389
%
, *
, +
, -
, /
(arithmetic) operators, 87
%
, *
, +
, -
, /
operator overloading 387–389
++
/--
(increment/decrement) operators, 97–102
+
, -
(unary plus/minus) operators, 86–87
+
, +=
, -
, -=
delegate operators, 540–542
=
assignment operators, 15
?:
(conditional) operators, 119–120
??
(null coalescing) operators, 120–121
(escape sequence), 44
^
(exclusive OR) operators, 118, 122
{}
(curly braces), 2, 10, 110–114
||
(OR) operators, 116, 117, 122
with flag enums, 365
~
(bitwise complement) operators, 127, 64
Abort()
method, 740
abstract classes
compared to interfaces, 337
abstract members, 302, 303–304, 305
access modifiers, 227–229, 397–398
private,
227–229, 284–285, 397–398
protected internal
, 398
on property getters/setters, 239–240
on classes, 397
array accessors, 74
Active Template Library. See ATL
Add()
method, 249, 352, 473, 568–569, 641
add/remove
event handlers, customizing, 558
aliases qualifiers
addition (+) operators, 87, 387, 541
guidelines, 91
advanced parameters, methods, 175–184
AggregateException,
547, 757–764, 768, 779, 798–800
aggregation for multiple inheritance, 287–290
algorithms
hill climbing, 798
mark-and-compact, 407
mark-and-sweep-based, 882
work stealing, 798
aliasing with using, 171, 401–402
data on call stacks, 868
virtual memory, 851
AllocExecutionBlock()
method, 855
AllowMultipleAttribute
parameter, 700
alternative statements, 107
AND (&&
) operator, 117–118, 122–126
with flag enums, 365
anonymous methods, 495, 512–514
anonymous types, 56–57, 562–564, 566–568
projecting to, 583
antecedent tasks, 753
APIs (application programming interfaces), 27
APM (Asynchronous Programming Model), 908–921
AppDomain, 762
application programming interfaces. See APIs
Appointment
class, 278
ArgumentException,
424
ArgumentNullException,
424
ArgumentOutOfRangeException,
424
arguments
command-line, passing, 173
named, 191
arithmetic (binary) operators, 87–96,
access, 68
command-line options, 80
literal values, 71
redimensioning, 78
runtime, defining size at, 72
three-dimensional, 73
two-dimensional, 69, 72, 74–75
as
operator, conversions, 310–311
AsParallel()
method, 584
assemblies, 4. See also libraries
metadata, viewing, 678. See also reflection
versioning, 889
well-formed types, referencing, 393–398
Assert()
method, 95
assigning
arrays, 68
null
to strings, 54
text, 42
assignment operators
applying, 548
binary operators, combining with, 389
events, 541
associating
classes, 259
data types, 57
relationships, 217
associativity, 88
async
keyword, 777–781, 937–942
asynchronous delegate invocation, 921–924
asynchronous programming, 732
high-latency operations, 772–777
System.Threading.Thread
class, 737–739
Task-based Asynchronous Pattern (TAP), 770–794
task-based asynchrony, 848–849
ATL (Active Template Library), 287
atomic operation, 734, 745, 829
backward compatibility, 712
constructors, initializing, 694–699
FlagsAttribute
class, 367, 701–702
IndexerNameAttribute,
657
interfaces, comparing, 337–338
naming, 692
predefined, 703
System.AttributeUsageAttribute
class, 699–700
System.ConditionalAttribute
class, 703–705
System.ObsoleteAttribute
class, 705–706
System.SerializableAttribute
class, 438, 713–714
automatically shimmed interfaces, 848
automatically implemented properties, 232–234
Average()
method, 609
await
keyword, 741, 777–781, 937–942
background worker patterns, 928–932
backing field declarations, 232, 244
backslash () escape sequence, 44
Base Class Library. See BCL
finalizers in, 412
inheritance, overriding, 290–302
refactoring, 279
base types, 212
BCL (Base Class Library), 25, 34, 743, 885, 892, 894
BeginGetResponse()
method, 908
BeginX()
method, 908
behaviors
implementation-defined, 101
polymorphism, data types, 310
best practices, thread synchronization design, 827–829
binary floating-point types, 37, 92–96
binary (arithmetic) operators, 87–96, 387–389
BinarySearch()
method, 643, 644
BinaryTree<T>
class, 462–463, 658
binding
late, 893
methods, 714
runtime, XML elements, 719–720
bitwise
complement ()
operators, 127, 644
compound assignment operators, 126
blocks
catch, 199–200, 203, 204, 428–432
try, 197
Boolean
number conversions, 64
types, 43
Break()
method, 803
breaking parallel loops, 803–804
brittle base classes, 295
bugs, runtime performance, 885–886
building custom collections, 635. See also collections, customizing
C language, 1
pointers, declaring, 865
arrays, declaring, 69
buffer overrun, 76
delete
operator, 216
deterministic destruction, 418, 882
evaluation order of operands, 90
global methods, 164
global variables/functions, 256
header files, 168
implementation-defined behavior, 101
implicit overriding, 292
implicitly typed variables, 565
local variable scope, 114
Main method, 10
methods, calling, 295
multiple inheritance, 287
operator errors, 115
operator-only statements, 87
pointers, declaring, 865
preprocessors, 145
pure virtual functions, 305
short
data types, 35
string concatenation at compile time, 48
struct,
defining with public members, 348
switch
statements, 138
templates, 466
void,
55
caches, avoiding repeated, 590
calculating
compound assignment operators, 96–103
financial, 36
operators, 86. See also operators
values, bytes, 122
callers, 157
variables, matching with parameter names, 176
calling
constructors, 245
statements, 163
P/Invoke
sites, 175
Task.ContinueWith
method, 752, 789
Cancel()
method, 766
CancellationToken
class, 764, 767
CancellationTokenSource
class, 767
parallel loops, 800
PLINQ queries, 807
Capacity()
method, 639
capitalizing variables, 15
capturing
variables, 518
CAS (code access security), 884
permissions, 686
case-sensitivity, 2
multiple strings, 43
cast (()
) operators, 61, 391–392
casting
inheritance, chaining, 282–283
multicast delegates, 533
operators, defining, 283
catch blocks, 199–200, 203, 204, 428–432
catch
clause, 779
catching exceptions, 196–197, 426–427
categories of types, 57–60, 340
centralizing initialization, 252–253
chaining
inheritance
exceptions, 437
multicast delegates, 544
change()
method, 942
char
data types, 92
characteristics of parameter arrays, 183
@, 47
escape, 45
checking
types, 883
child collections, formatting, 602
Church, Alonzo, 513
CIL (Common Intermediate Language), 24, 876, 877, 894
boxing, 350
empty catch blocks, 432
extension methods, 266
indexers, 657
iterators, defining, 661
machine code, compilation to, 879–880
objects
deriving, 309
initializers, 248
outer variables, implementing, 520–521
Stack<T>
class, 490
System.SerializableAttribute
class, 713–714
circumventing encapsulation, 883
class
keyword constraints, 468–469
access modifiers, 227–229, 397
associating, 259
base. See also base classes
refactoring, 279
common initializers, 249
defaults, 247
definitions, 214
finalizers, 416
inheritance, 277. See also inheritance
instances
interfaces
conversions, 326
Java inner classes, 272
locations, 408
members, 216
memory, garbage collection, 408
methods, 157. See also methods
object-oriented programming, 210–213
access modifiers on getters/setters, 239–240
sealed, inheritance, 290
cleanup
collection interfaces after iteration, 575
resources
APM, 914
using
statements, 575
CLI (Common Language Infrastructure), 1, 24–26, 894, xxvii
application domains, 887
BCL, 892
CIL, 890
CTS, 891
closed over variables, 518
CLR (Common Language Runtime), 881, 894
CLS (Common Language Specification), 25, 877, 891–892, 895
CLU language, 660
COBOL, 890
code, xxiii
native, 24
preprocessor directives, excluding/including, 146–147
reuse, 394
unsafe, 845–846, 863–864, 867, 872–873
whitespace, formatting, 13
child, formatting, 602
customizing, 635
dictionaries, 636, 646–650, 696
filtering, 614
generics, 637
interfaces, 249, 561–562, 636–638
creating multiple in single classes, 673–674
defining, 661
recursive, 669
yield break
statements, 670–671
yield return
statements, 674
multiple items, searching, 645
projecting, 614
queues, 654
total ordering, 643
yield return
statements, placing in loops, 667–669
collisions, type names, 158
COM (Component Object Model)
DLL registration, 890
STAThreadAttribute
class, 842–843
combining assignment operators with binary operators, 389
command-line
arguments, passing, 173
array options, 80
CommandLine
class, 270
CommandLineAliasAttribute
class, 694
CommandLineInfo
class, 681, 684, 688, 689
CommandLineSwitchRequired-Attribute
class, 692, 694
preprocessor directives, 145
xcopy,
889
commas (,), 165
comments
XML, 678
Common Intermediate Language. See CIL
Common Language Infrastructure. See CLI
Common Language Runtime. See CLR
Common Language Specification. See CLS
Common Type System. See CTS
Compare()
method, 495
generics, 463
ComparisonHandler
delegate, 499
comparisons
equality, requirements of, 651
interfaces
compilers, 878
paths, configuring, 898
compiling
checked/unchecked conversions, 63
just-in-time compilation, 24, 466, 879
keywords, 4. See also keywords
static compilation versus dynamic programming, 720–721
components, 1
composite formatting, 20
compound assignment operators, 96–103
Concat()
method, 608
concatenation, strings
at compile time, 48
conditional logical operators, 389
conditional (?:
) operators, 119–120
consequence statements, 107
consistency, integers, 35
console executable assemblies, 394
ConsoleListControl
class, 316–317, 320
consoles
Console.WriteLine()
method, 340, 352, 871
const
values, 267
constants
fields, declaring, 267
math, 112
public, 268
constructors, 470
multiple, 469
attributes, initializing, 694–699
base, specifying base, 301–302
common initializers, 249
defaults, 247
generics, defining, 457
Contains()
method, 643
context
switches, 732
contextual keywords, 6, 672–673
continuation
passing style. See CPS
tasks, 789
ContinueWith()
method, 753, 775, 919–920
contravariance
asynchronous tasks, 751
statements, 85, 103–110, 127–139
exception-handling, 198
tasks, 780
conversions
Boolean types, numbers, 64
CIL, 879
classes, interfaces, 326
covariant, 482. See also covariance
exception handling without, 207
explicit, 392
objects, deriving, 282
strings, 65
checking, 883
cooperative cancellation, 764
CopyTo()
method, 638
cores, 730n2
Count()
method, 585–586, 609, 622
Count
property, 638
CountdownEvent
class, 835
CountLines()
method, 157
CPS (continuation passing style), 911–913, 915
CPUs (central processing units), 730
LINQ queries, running in parallel, 584
CTS (Common Type System), 25, 877, 891, 895
add/remove
handlers, 558
collections, 635. See also collections
queues, 654
searching items, 645
searching List<T>
class, 643–644
total ordering, 643
dictionaries, equality, 649–650
LINQ, providers, 609
methods, asynchronous, 783–786
synchronization contexts, 790
managed, 881
persistence to files, 224
retrieval from files, 225
DataStorage
class, 403
de-allocating objects, 882. See also allocating
decrement (--
) operators, 97–102
default
keyword, 68
default constructors, 247
default constructor constraints, 474–476
deferred execution
implementing, 623
query expressions, 619
standard query operators, 586–590
#define
preprocessor directive, 147–148
delegate
keyword, 542
delegates, 495
asynchronous delegate invocation, 921–924
sequential invocation, 542
generics, declaring types, 552
instances, returning, 539
invoking
multicast, 533
P/Invoke, 862
passing, 510
sequence diagrams, 545
synchronous, 747
syntax, 502
System.Func/System.Action,
514–530
types, declaring, 500
unsafe code, executing via, 872–873
delete
(C++) operator, 216
delimited comments, 22
denominators, 35
deployment, xcopy, 889
Dequeue()
method, 654
dereferencing pointers, 869–871
deriving
casting between types, 281–282
customizing conversions, 283–283
private
access modifiers, 284–285
protected
access modifiers, 285–286
types, 212
deserialization, 711. See also serialization
deterministic destruction (C++), 418, 882
deterministic finalization, 412–415
device drivers, 886
dictionaries
collections, 636, 646–650, 696
equality, customizing, 649–650
directives. See also commands
#pragma
preprocessor directive, 149
specifying line numbers, 150
DirectoryCountLines()
method, 185, 187, 191
Directory.GetFiles()
method, 617
DirectoryInfoExtension.Copy()
methods, 260
DirectoryInfo.GetFiles()
method, 597
disabling parallelism, 802
disambiguating multiple Main()
methods, 174
Dispose()
method, 6n6, 413, 416, 575
tasks, 770
distribution, APM parameters, 911
division (/
) operators, 87
DLL (Dynamic Link Library), 4
COM registration, 890
do/while
loops, control flow statements, 127–129
documents
domains, applications, 887
dot (.
) operator, 871
DotGNU, 878
dotPeek, 30
double quotes ("), 47
double.TryParse()
method, 207
downloading .NET (Microsoft), 897–899
drivers, devices, 886
duck typing, 576
Dump()
method, 325
Dynamic Link Library. See DLL
dynamic objects
static compilation versus, 720–721
dynamic programming, 677
EAP (Event-based Asynchronous Pattern), 924–927
elements
deleting, 641
indexes, retrieving, 640
#elif
preprocessor directive, 146–147
else
clauses, 107
#else
preprocessor directive, 146–147
empty catch blocks, 432. See also catch blocks
empty memory, retrieving, 246
Empty<T>
method, 659
circumventing, 883
of types, 396
encryption. See also security
serialization, 708
strings, 804
EndGetResponse()
method, 908
#endif
preprocessor directive, 146–147
#endregion
preprocessor directive, 151–152
EndX()
method, 908
Enqueue()
method, 654
Enter()
method, 353
EntityBase
, EntityBase<T>
class, 468, 471
EntityDictionary
, EntityDic-tionary<T>
class, 469, 476
enumeration, values, 702
equality, 93. See also inequality
dictionaries, customizing, 649–650
structural, delegates, 516–517
equals (==
) operator, 386
#error
preprocessor directive, 148–150
buffer overrun, 76
handling
platform interoperability/unsafe code, 854–856
sequential notification, 544–547
using
statements, 575
infinite recursion, 186
namespace alias qualifiers, 401
operators, 115
preprocessor directives, 148–150
rounding, 37
Windows Error Reporting, 425
escape sequences, 44
verbatim string literals, 47
Etch A Sketch, 444
evaluation, 89
order of operands, 90
Event-based Asynchronous Pattern. See EAP
sequential invocation, 542
handlers
implementing, customizing, 558–559
notifications
firing, 553
publishers
connecting subscribers and, 536–537
defining, 536
examples of iterators, 666–667
AggregateException,
547, 757–764, 768
parallel loop exception handling, 798–800
ArgumentException,
424
ArgumentNullException,
424
ArgumentOutOfRangeException,
424
asynchronous high-latency operations, 775–776
classes, inheritance, 201
common exception types, 202
defining custom exceptions, 435–438
handling, 423
multiple exception types, 424–425
hiding, 432
InnerExceptions
property, 760
InvalidAddressException,
435
InvalidCastException,
353, 464
InvalidOperationException,
427, 439
NotImplementedException,
321
NullReferenceException,
424, 538, 551, 659, 826
OperationCanceledException,
807
OutOfMemoryException,
433
reporting, 433
sequences, diagrams, 545
serializable, 438
specifiers, 427
SqlException,
437
StackOverflowException,
433
suffixes, 437
System.ComponentModel.Win32Exception,
854
System.FormatException,
198, 199
System.InvalidCastException,
393
System.Runtime.Serialization.Serialization-Exception,
710
TaskCancelledException,
767, 768
ThreadAbortException,
741, 742
arrays, 75
checked/unchecked conversions, 63
deserialization, 711
UnauthorizedAccessException,
438
excluding code, preprocessor directives, 146–147
exclusive OR (^
) operator, 118, 122
execution
agents, 881
deferred
implementing, 623
query expressions, 619
standard query operators, 586–590
delegates, unsafe code, 872–873
managed, 881
Exit()
method, 353
explicit conversions, 392
explicit deterministic resource cleanup, 216
explicit member implementation, 322–323
exponential notation, 40
expressions
generics, 6n6
asynchronous programming, 782–783
expression trees, 524
lazy loading, 420
queries
Extensible Markup Language. See XML
extensions
IEnumerable<T>
interface, 562
inheritance, 287
Reactive Extensions library, 729
external functions
f-reachable queues, 416
factory interfaces, 475
factory methods, 461
FCL (Framework Class Library), 892, 895
features, adding, 278. See also inheritance
Fibonacci numbers/series, 128, 351
fields, 51
constants, declaring, 267
readonly
modifiers, declaring, 268, 269
volatile,
declaring as, 823–824
files
data
persistence to, 224
retrieval from, 225
headers, 168
loading, 224
references, assemblies, 889
storing, 224
XML, 23, 402–407. See also XML
FileSettingsProvider,
329
FileStream
property, 419
filtering
collections, 614
System.Linq.Enumerable.Where(),
568–569
finalizers, 249–250, 347, 410–412
FindAll()
method, 645
first in, first out (FIFO), collections, 654
flags
values, 702
FlagsAttribute
class, 367, 701–702
floating-point types, 35–36, 92–96, 351
flow control, 730. See also control flow statements
IEnumerable<T>
interface, 572–577
ForEach()
method, 801
foreground threads, 739
formal declaration, methods, 165–166
format items, 20
Format()
method, 48
format strings, 20
formatting
if/else
statement sequences, 109
indentation, code blocks, 111
numbers as hexadecimal, 41
string length, 51
variables, 15
FORTRAN, 890
fractions, 35
fragile base classes, 295
frames, removing activation, 175
Framework (Microsoft .NET), 878
Framework Class Library. See FCL
frameworks, 877
FROM
clause, 615
from
clause, flattening sequences, 630–632
FromCurrentSynchronizationContext()
method, 788
full outer joins, 594
functionality, CLI, 888n5
functions
external
global, 256
pointers, 862
fundamental numeric types, 34–43
value types, 347
gating parallelism, 802
GC.ReRegisterFinalize()
method, 419
general catch blocks, 203, 428–432
general-purpose delegates, System.Func/System.Action,
514–530
generating
anonymous types, 568
XML documentation files, 405–407
generics, 443
collections, interface hierarchies, 637
constructors, defining, 457
default values, specifying, 458–459
delegates, declaring types, 552
expressions, 6n6
finalizers, defining, 457
instantiation
Java, 493
lazy loading, 420
multiple type parameters, 459–460
GetCustomAttributes()
method, 694
GetDynamicMemberNames()
method, 724
GetEnumerator()
method, 576, 577, 610, 661, 662, 664, 787n8
GetFiles()
method, 157
GetFirstName()
method, 232
GetFullName()
method, 166
GetGenericArguments()
method, 687
GetHashCode()
method, 349, 373–376, 651
GetInvocationList()
method, 547, 548
GetLength()
method, 79
GetName()
method, 219
GetResponse()
method, 772
GetResponseAsync()
method, 779
GetReverseEnumerator()
method, 673
GetSetting()
method, 327
GetSummary()
method, 305
GetSwitches()
method, 696
getters, 51
accessibility, modifying, 237–239
declaring, 230
GetUserInput()
method, 166
GetValue()
method, 685
GhostDoc, 406n3
global functions, 256
global methods, 164
global variables, 256
graphs, expression trees, 525–527
GreaterThan
method, 507
groupby
clause, 627
GroupBy()
method, grouping results, 600–601
grouping
encapsulation, 215
methods, 502
namespaces, 158
statements into methods, 156–157
types, defining namespaces, 398–402
GroupJoin()
method, 613
guest computers, 872
addition (+
) operators, 91
anonymous methods, 513
attributes
assemblies, 692
AttributeUsageAttribute
class, 700
constructors, 699
custom, 693
catch blocks, 204
classes
access modifiers, 240
collections, 649
comments, 23
constants, fields, 267
constructors
defaults, 248
naming, 251
conversion operators, 393
Count()
method, 586
covariance, 489
curly braces ({}), 112
custom collections, 643
delegates, types, 515
empty collections, 660
Equals()
method, 385
events, declaring, 554
exceptions
customizing, 437
multiple exception types, 425
reporting, 435
wrapping, 439
extension methods, 266
finalizers, 417
generics
implementing multiple interfaces, 457
methods, 481
type parameters, 462
goto
statements, 145
identifiers, 7
if/else
statements, 120
increment/decrement operators, 101
integers, 35
interfaces
adding members, 335
attributes, 338
comparing to classes, 337
explicit/implicit implementations, 324–325
implementations, 326
multiple inheritance, 333
naming, 315
lambda parameters, 509
literal suffixes, 40
local variables, 15
locking, avoiding, 823
long-running tasks, 770
managed wrappers/unmanaged methods, 856
methods, naming, 157
multiple type parameters, 460
aborting threads, 743
thread pools, 745
Thread.Sleep()
method, 741
unhandled exceptions, 764
nested classes, 272
.NET (Microsoft), 6
null,
invoking delegates, 539
OrderBy()
/ThenBy()
methods, 592
P/Invoke, 862
parallel loops, 797
parentheses (()), 90
get-only, 239
validating, 237
query expressions, 634
static initialization, 262
switch
statements, 137
synchronization, avoiding, 823
System.EventHandler<T>
class, 555
thread synchronization, 811–841
ToString()
method, 373
types, naming parameters, 453–454
value types
avoiding mutable types, 355
creating enums, 361
defaults, 347
defining structs, 369
direct enum/string conversions, 365
enum underlying types, 360
flag enums, 366
immutable, 345
memory, 341
overloading equality operators, 349
XML comments, 407
Handle()
method, 760
handlers, events
handling
errors
platform interoperability/unsafe code, 854–856
sequential notification, 544–547
using
statements, 575
exceptions, 423
asynchronous high-latency operations, 775–776
background worker patterns, 931–932
defining custom exceptions, 435–438
multiple exception types, 424–425
exceptions, parallel loops, 798–800
hash codes, 651
headers, files, 168
heaps
memory, 349
static
keyword, 255
Help
property, 689
hiding exceptions, 432
hierarchies
interfaces, generic collections, 637
organizing, 161
high-latency operations, invoking, 771–772, 772–777
hill climbing, 798
hot tasks, 748. See also tasks
Hyper-Threading, 730
IAngle.MoveTo
interface, 354
IAsyncAction<T>
interface, 848, 849
ICollection<T>
interface, 638
IComparable
interface, 323, 324
IComparable<T>
interface, constraints, 465
IComparer<T>
class, 495
keywords as, 8
namespaces, nesting, 400
IDictionary<T>
interface, 636–638
IDisposable
interface
resource cleanup with, 413
tasks, 770
IDispose()
method, 915
IDistributedSettingsProvider
interface, 335
IEnumable<T>
interface, 571–577
IEnumerable
interface, 331
IEnumerable<T>
interface, 616n1
extension methods, 562
query expressions, 616
standard query operators, 577–610
if/else
statements, guidelines, 120
#if
preprocessor directive, 146–147
IFileCompression
interface, 314, 315
IFormattable
interface, 357
IListable
interface, 331
ILMerge
utility, 889
ILSpy, 30
implementation-defined behavior, 101
implementing
conversion operators, 392
deferred execution, 623
dynamic objects, 714
Equals()
method, 382
interfaces, 313–315, 316–319, 320–326, 456–457
members
multiple inheritance, interfaces, 331–334
new
operator, 246
object-oriented programming, 210–213
one-to-many relationships, 601–604
properties, automating, 232–234
System.Runtime.Serialization.ISerializable
class, 709–710
implicit base type casting, 281
implicit deterministic resource cleanup, 216
implicit local variables, 562–568
implicit members, implementing, 323–326
implicit nondeterministic resource cleanup, 216
implicit overriding, Java, 292
implicitly typed local variables, 55–57
including code, preprocessor directives, 146–147
Increment()
method, 825
increment (++
) operators, 97–102
indenting
code blocks, 111
whitespace, 12
IndexerNameAttribute,
657
indexers
indexes, retrieving elements, 640
IndexOf()
method, 643
inequality, floating-point types, 93–96
infinity
negative, 96
recursion errors, 186
infrastructure, CLI, 875–877. See also CLI
inheritance, 211–212, 277, 310–311
aggregation, 289
base classes
chaining
exceptions, 437
classes, exceptions, 201
casting between types, 281–282
customizing conversions, 283–283
private
access modifiers, 284–285
protected
access modifiers, 285–286
extension methods, 287
is
operator, verifying underlying type, 309–310
multiple, 287
polymorphism, 306
sealed classes, 290
System.object,
deriving classes, 308–309
initialization
anonymous types, arrays, 570–571
clauses, 132
collection initializers, 568–571
NextId,
261
static, 262
static fields, 257
Initialize()
methods, 236
initializers
common, 249
constructors, 251
initializing attributes, constructors, 694–699
inner classes, Java, 272
inner joins, 593
InnerExceptions
property, 437, 439, 760
inserting newline (
) characters, 46
installing .NET (Microsoft), 897–899
instances
applications, formatting single, 829–830
delegates, returning, 539
fields, 217–219. See also static fields
polymorphism, 321
instantiation, 10
generics
42 as, 195
adding, 351
integral types, 91
IntelliSense, enabling, 615
attributes, comparing, 337–338
automatically shimmed, 848
classes
conversions, 326
implicit local variables, 564–565, 566–568
factory, 475
hierarchies, generic collections, 637
IAngle.MoveTo,
354
ICollection<T>,
638
IComparable<T>,
465
IDisposable
resource cleanup with, 413
tasks, 770
IEnumerable,
331
IEnumerable<T>
extension methods, 562
query expressions, 616
standard query operators, 577–610
IFormattable,
357
implementing, 316–319, 320–326
IObsolete,
338
IOrderedEnumerable<T>,
592
IReadOnlyPair<T>,
484
ISerializable,
709
ITrace,
325
multithreading, prior to TPL and C# 5.0, 907–936
naming, 315
PairInitializer<T>,
487
parameters, 192
internal
access modifier, 397
internals
interoperability, 25
languages, 25
Intersect()
method, 608
InvalidAddressException,
435
InvalidCastException,
353, 464
InvalidOperationException,
427, 439
InvokeRequired
property, 932
invoking
asynchronous delegate invocation, 921–924
delegates
exception sequence diagrams, 545
sequences, 542
finalizers, 412
high-latency operations, 771–777
methods, query expressions, 632–634
reflection, dynamic objects, 714–716
type members, 678. See also reflection
IObsolete
interface, 338
IOrderedEnumerable<T>
interface, 592
IProducerConsumer-Collection<T>
class, 835
IQueryable<T>
interface, 609–610
IReadableSettingsProvider
interface, 327
IReadOnlyPair<T>
interface, 484
is
operator, verifying underlying types, 309–310
IsAlive
property, 740
IsBackground
property, 739
IsCancellationRequested
property, 766, 767, 801
IsCompleted
property, 750, 804
ISerializable
interface, 709
ISettingsProvider
interface, 327
IsKeyword()
method, 620
items
collections, searching, 645
format, 20
Items
property, 456
iterations
collection interfaces, 573
continue
statements, 141
long-running loops, 802
iterators
creating multiple in single classes, 673–674
defining, 661
struct
versus class,
670
yield break
statements, 670–671
yield return
statements, 674
recursive, 669
ITrace
interface, 325
IWriteableSettingsProvider
interface, 329
Java, 1
arrays, declaring, 69
classes, naming, 4
exceptions, specifiers, 427
generics, 493
implicit overriding, 292
inner classes, 272
Main method, 10
virtual methods, 291
JavaScript, implicitly typed variables, 565
jitting, 879
joining
collections, 593
data types, 57
just-in-time compilation, 24, 466, 879
JustDecompile, 30
keys, 637
class,
constraints, 468
contextual, iterators, 672–673
default,
68
delegate,
542
as identifiers, 8
integers, 34
lock
operator,
392
private,
229
properties, defining, 232
static,
264
string,
avoiding locking, 822–823
chaining constructors, 251–253
try,
197
unchecked,
442
where,
465
lambda expressions, 495, 506–512
asynchronous programming, 782–783
expression trees, 524
lazy loading, 420
CIL, 876
CLI. See CLI
CLR, 881
CLU, 660
COBOL, 890
FORTRAN, 890
Pascal, 7
source, 890
last in, first out (LIFO), 444, 652
LastIndexOf()
method, 643
late binding, 893
latency, 728
invoking high-latency operations, 771–777
left outer joins, 593
length
strings, 51
assemblies, 394
ATL, 287
BCL, 25, 26, 34, 885, 892, 894
classes, 394
code, creating, 4
DLL, 4
Reactive Extensions library, 729
Task Parallel Library (TPL), 729, 790. See also TPL
limitations, constraints, 472–473
line-based statements (Visual Basic), 11
#line
preprocessor directive, 150
lines, specifying numbers, 150
linked lists, collections, 654–655
LinkedListNode<T>
class, 655
links, DLL, 4
LINQ
expression trees, 527
providers, customizing, 609
queries. See also queries
running in parallel, 584–585, 804–808
support, 27
Linux, installing platforms, 898
Liskov, Barbara, 660
listings
anonymous methods, passing, 512
APM patterns
accessing user interfaces, 933–934
asynchronous delegate invocation, 922–923
background worker patterns, 928–929
ContinueWith()
method, 919
invoking user interface objects, 935–936
invoking with callback/state, 911–912
System.Net.WebRequest
class, 908–909
arrays
accessing, 74
assigning, 70
command-line options, 80
declaring, 69
defining size at runtime, 72
errors, 72
initializing two-dimensional arrays of integers, 72
literal values, 71
methods, 77
new
keyword, 71
retrieving dimension size, 79
swapping data, 74
three-dimensional, 73
throwing exceptions, 75
two-dimensional arrays, 69, 72, 74–75
attributes
applying named parameters, 700
assembles within AssemblyInfo.cs,
690–691
AttributeUsageAttribute,
699–700
backward compatibility, 712
constructors, 695
decorating properties with, 689, 690
defining custom, 693
implementing System.Runtime.Serialization.ISerializable
class, 709–710
restricting constructs, 699
retrieving specific attributes, 695–696
specifying return attributes, 691
System.AttributeUsage-Attribute
class, 699–700
System.ConditionalAttribute
class, 703–705
System.ObsoleteAttribute
class, 705–706
System.SerializableAttribute
class, 713
updating CommandLineHandler.TryParse(),
697–699
case-sensitivity of multiple strings, 43
classes
access modifiers, 229
accessing fields, 218, 219–220
accessing static fields, 257–258
assigning static fields at declaration, 257
automatically implemented properties, 233–234
calling constructors, 245–246, 251–252
calling object initializers, 248, 249
CIL code from properties, 243–244
data persistence to files, 224
data retrieval from files, 225
declaring, 8
declaring constant fields, 267
declaring fields, 217
declaring getter/setter methods, 230
declaring static classes, 263–264
declaring static constructors, 261
declaring static fields, 256
declaring static properties, 262
declaring variables of class types, 214
defining, 213
defining constructors, 245
defining nested classes, 270–271, 273, 274–275
defining partial classes, 272–273
defining properties, 231, 240–242
defining read-only properties, 238
defining static methods, 259–260
explicit construct properties, 244
implicit local variables, 254
initialization methods, 253
instantiation, 215
overloading constructors, 250
passing this
keyword in method calls, 223
placing access modifiers on setters, 239–240
setting initial values of fields, 217
validating properties, 236
code blocks
if
statements, 110
indentation, 111
collection interfaces
filtering with System.Linq.Enumerable.Where(),
568–569
foreach
with arrays, 572
implicit local variables with anonymous types, 562–563
initializing anonymous type arrays, 570–571
iterating, 573
resource cleanup with using
statements, 575
separate enumerators during iteration, 574–575
comments, 21
control flow statements
do/while
loops, 129
foreach
loops, 134
if/else
formatted sequentially, 109
if/else
statements, 107
if
statements, 135
multiple expressions (for
loops), 132
nested if
statements, 108
while
loops, 127
custom collections
adding items to Diction-ary<T>
class, 647
applying Pair<T>.Get-Enumeator()
method, 667
applying yield
statements, 666
bitwise complement () operator, 644
defining index operators, 658–659
FindAll()
method, 645
implementing IComparer<T>
interface, 642
implementing IEquality-Comparer<T>
interface, 650
inserting items to Dictionary<T>
class using index operators, 647
iterating over Dictionary<T>
class with foreach,
648–649
iterator interface patterns, 661–662
List<T>
class, 640
modifying indexer default names, 658
yield break
statements, 670–671
yield return
statements, 673
yielding C# keywords sequentially, 663–664
delegates
applying method names as arguments, 501–502
BubbleSort()
method, ascending/descending, 497–498
BubbleSort()
method, parameters, 498–499
capturing loop variables, 521–522, 523
CIL code for outer variables, 520
CIL for lambda expressions, 517–518
declaring Comparison-Handler,
501
declaring Func/Action,
514–515
declaring nested types, 500
declaring types, 500
expression trees, 525
passing as parameters, 502
viewing expression trees, 528–530
dynamic objects
equality operators, overriding, 376–380
Equals()
method, overriding, 383–384
escape sequences, 44
events
applying assignment operators, 548
connecting publishers/subscribers, 536–537
custom add/remove
handlers, 558
custom delegate types, 554–555
declaring generic delegate types, 552
declaring OnTemperature-Change
event, 556
defining Heater/Cooler
objects, 534–535
defining publishers, 536
firing, 549
firing notifications, 553
handling exceptions from subscribers, 546–547
OnTemperatureChanged()
method, 544
exceptions
customizing, 436
defining serializable, 438
overflowing integer values, 440
throwing, 424
explicit casts, 61
generics
arity, 460
BinaryTree<T>
class, 462–463, 480
CIL code for Stack<T>
class, 490
CIL with Exclamation Point Notation, 491
combining constraints, 473–474
combining covariance and contravariance, 487
compile errors, 458
compiler validation of variance, 488
constraint expressions, 473
contravariance, 486
converting generics, 482
covariance using out
type parameter modifier, 484
Create()
method, 461
declaring class type constraints, 467
declaring constructors, 457
declaring generic classes, Stack<T>,
452
declaring interface constraints, 465
declaring interfaces, 454
declaring nullable types, 449
declaring variables of type scatter<T>,
491
declaring versions of value types, 448
default constructor constraints, 470, 475
default
operator, 458
defining methods, 477
defining specialized stack classes, 447
duplicating interface implementations, 456
EntityDictionary<T>
class, 476
factory interfaces, 475
implementing interfaces, 455
implementing Undo with Stack
class, 450–451
inferring type arguments, 478
inheritance constraints, 474
inheritance constraints, specified explicitly, 471
interface support, 463
multiple constraints, 469
multiple type parameters, 459, 460
nested types, 462
repeating inherited constraints, 472
specifying constraints, 479–480
specifying type parameters, 478
struct/class
keywords, 468
System.Collections.Stack
method signatures, 444
System.Delegate
class, 504
type parameter support, 464
GetHashCode()
method, overriding, 375
HelloWorld,
2
breaking apart, 9
hexadecimal notation, 41
implicit conversions, 64
implicit local variables, 56–57
inheritance
accessing base members, 300
accessing private members, 284
accessing protected members, 285–286
applying methods, 280
applying polymorphism, 306–307
defining abstract classes, 303
defining abstract members, 303–304
defining cast operators, 283
implicit base type casting, 281
is
operator determining underlying type, 309
as
operator conversions, 310–311
overriding properties, 291
preventing derivation, 290
Run()
method, 294
sealing members, 299
single using aggregation, 288
specifying base constructors, 301–302
System.Object
derivation, 309
integers, overflowing values, 62
interfaces
applying base interfaces in class declarations, 328
calling explicit member implementations, 322
declaring explicit members, 327
defining, 315
explicit interface implementation, 322–323
implementing, 316–319, 320–321
multiple inheritance, 329
single inheritance using aggregation, 331–332
lambda expressions
omitting parameter types, 508
parameterless statements, 509
passing delegates, 510
single input parameters, 509
statements, 507
for
loops, 130
Main()
method, 10
methods
calling, 158
converting a string
to an int,
194
counting lines, 184–185, 187–189
finally blocks without catch blocks, 199–200
general catch blocks, 203
passing command-line arguments, 173
passing return values, 162
passing variable parameter lists, 181–182
passing variables by reference, 177–178
passing variables by values, 175–176
passing variables out only, 179–180
rethrowing exceptions, 206
return
statements, 167
specifying parameters by names, 191–192
multiple statements on one line, 12
multithreading
applying Task.Factory.StartNew()
method, 769
asynchronous Web requests, 773–774, 777–778
calling Task.ContinueWith
method, 752, 789
cancelling parallel loops, 800–801
cancelling PLINQ queries, 807–808
customizing asynchronous methods, 784–785, 785–786
handling tasks, unhandled exceptions, 758–759
invoking asynchronous tasks, 747–748
iterating over await
operations, 792–793
LINQ Select()
method, 804
observing unhandled exceptions, 760–761
parallel execution of foreach
loops, 797
PLINQ Select()
method, 805
PLINQ with query expressions, 806
polling Task<T>
classes, 749
registering for notifications, 756
registering for unhandled exceptions, 762–763
synchronous high-latency invocation with WPF, 791–792
synchronous Web requests, 772–773
unhandled exception handling, parallel iterations, 799
character, 46
no indentation formatting, 12
nullable modifiers, 60
operators, 86
AND (&&), 118
bitwise, 124
char
data types, 92
character differences, 92
common increment calculations, 97
conditional, 119
constants, 103
decrement (- -), 98
dividing a float by zero, 95
equality, 116
examples of assignment, 97
increment (++), 97
inequality with floating-point types, 94–95
logical assignment, 126
negative values, 87
non-numeric types, 91
NOT, 118
null coalescing, 120
overflowing bounds of float,
96
post-increment, 99
pre-increment, 99
prefix/postfix, 100
relational, 116
Unicode values in descending order, 98
Parse()
method, 65
placeholders, 20
platform interoperability/unsafe code
accessing referent type members, 871–872
allocating data on call stacks, 868
applying ref/out
rather than pointers, 852
declaring external methods, 849–850
declaring types, 853
designating unsafe code, 863, 872–873
invalid referent types, 866
modifying immutable strings, 869–870
wrapping APIs, 861
#pragma
preprocessor directive, 149
preprocessor directives, 147
#define,
147
excluding/including code, 147
#region/#endregion,
151
#warning,
148
query expressions, 614–615, 632–633
anonymous types, 618
continuation, 630
multiple selection, 630
ordering results, 616
projection using, 617
selecting anonymous types, 628–629
sorting, 624
sorting by file size, 625
standard query operator syntax, 633
reflection
declaring Stack<T>
class, 686
dynamic programming using, 715
dynamically invoking members, 681–684
using Type.GetProperties()
method, 679–680
using typeof()
method, 680
round-trip formatting, 42
single statements, splitting, 12
standard query operators
calling SelectMany()
method, 604–605
counting items, 585
creating child collections, 602
executing LINQ queries in parallel, 584
filtering with System.Linq.Enumerable.Where()
method, 581, 586–587
projection to anonymous types, 583
projection with System.Linq.Enumerable.Select()
method, 582
sample employee/department data, 594–596
System.Linq.Enumerable()
method calls, 606–607
strings
assigning null
to, 54
binary displays, 125
immutable, 52
implicitly typed local variables, 55–56
length, 51
System.Console.ReadLine()
method, 17–18
System.Console.WriteLine()
method, 19–20
System.Convert
class, 65
System.Threading.Timer
class, 941–942
System.Timers.Timer
class, 939–940
thread synchronization, 811–841
creating single instance applications, 829–830
firing event notifications, 826
lock
keyword, 820
System.Threading.Interlocked
class, 824–825
Task.Delay()
method, 842
thread-safe event notification, 826
ThreadLocal<T>
class, 838
ThreadStaticAttribute
class, 839–840
unsynchronized local variables, 815–816
unsynchronized state, 813
Tic-Tac-Toe
source code, 901–905
ToString()
method, 65, 372–373
unchecked blocks, 63
Unicode characters (smiley faces), 45–46
value types
accessing properties, 346
avoiding copying/unboxing, 357
boxing idiosyncrasies, 353
boxing/unboxing instructions, 351
casting between arrays/enums, 362
comparing integer switches/enum switches, 358
converting strings to enums, 363
declaring enums, 359
default
operator, 348
defining enum values, 366
defining enums, 359
enums as flags, 364
FlagsAttribute,
367
initializing structs, 346
OR/AND operators with flag enums, 365
referencing Equals()
method, 381
unboxing to underlying types, 353
variables
assigning, 16
declaring, 13
modifying values, 15
one statement, declaring with, 15
scopes, 113
verbatim string literals, 47
well-formed types
applying alias directives, 402
calling binary operators, 388
comparison operators, 386
conversion operators, 392
defining finalizers, 411
defining namespaces, 399
invoking using
statements, 415
lazy loading properties, 419, 420
making types available, 396
nesting namespaces, 400
overloading unary operators, 390, 391
resource cleanup, 413
weak references, 409
whitespace, removing, 12
lists
collections, 640
formal parameters, 165
type parameters, 165
literals
arrays, 71
readonly
fields, 269
loading
files, 224
lazy. See lazy initialization
local negation (!
) operator, 118–119
local storage, threads, 837–841
local variables, 14
scope, 114
locations
keywords, 4
objects, 408
lock
keyword
lock
statements, 736
consoles, synchronization, 920–921
multithreading, 736
lockTaken
parameter, 819
logical Boolean operators, 116–121, 122–126
Logon()
method, 228
long-running
loops, 802
loops
decrement (--
) operators, 98
do/while,
control flow statements, 127–129
executing, iterations in parallel, 794–804
IEnumerable<T>
interface, 572–577
iterations, 129
parallel
executing iterations in, 794–804
while,
control flow statements, 127–129
yield return
statements, placing in, 667–669
LowestBreakIteration
property, 804
52.14.181.129