& (ampersands). See Ampersands (&)
<> (angle brackets)
generics, 540
XML, 33
* (asterisks). See Asterisks (*)
@ (at signs)
verbatim strings, 60
(backslashes)
as literals, 60
^ (carets). See Carets (^)
: (colons). See Colons (:)
, (commas). See Commas (,)
{} (curly braces). See Curly braces ({})
$ (dollar signs) for string interpolation, 28, 61–62
" (double quotes)
= (equals signs). See Equals signs (=)
! (exclamation points). See Exclamation
points (!)
/ (forward slashes). See Forward slashes (/)
> (greater than signs). See Greater than signs (>)
# (hash symbols) for preprocessor directives, 186
- (hyphens). See Minus signs (-)
< (less than signs). See Less than signs (<)
- (minus signs). See Minus signs (-)
() (parentheses). See Parentheses ()
% (percent signs)
compound assignment, 132
precedence, 124
remainder operation, 123
. (periods)
fully qualified method names, 198
null-conditional operator, 158
+ (plus signs). See Plus signs (+)
? (question marks)
command-line option, 783
conditional operators, 154–155
null-coalescing operator, 157–158
null-conditional operators, 158–160
; (semicolons)
ending statements, 20
preprocessor directives, 189
' (single quotes)
characters, 57
escape sequence, 57
[] (square brackets)
indexers, 750
null-conditional operators, 158–160
~ (tildes)
complement operator, 167
finalizers, 494
list searches, 736
overriding, 468
_ (underscores). See Underscores (_)
| (vertical bars)
bitwise operators, 164
compound assignment, 167
a
escape sequence, 58
Abstract classes
overview, 357
abstract
modifier
interface refactoring, 405
Access modifiers
base class overriding, 353–354
finalizers, 495
Accessing
referent type members, 970
Accuracy of floating-point types, 128–129
Acronyms as identifiers, 15–16
Activation frames, 216
Add()
method
collection initializers, 298, 654–655
dictionaries, 739
interlocks, 927
lists, 733
Addition
binary operator, 123
compound assignment, 132
increment operator, 133
Address operator (&), 965
Addresses and pointers. See Pointers
AggregateException
type, 247
asynchronous requests, 859–860
publish-subscribe pattern, 640
wrapped exceptions, 517
Aggregation for inheritance, 345
Ahead of time (AOT) compilation, 993
Alerts escape sequence, 58
Aliases
Allow Unsafe Code option, 963
AllowMultiple
parameter, 795
AllowNull
attribute, 307
AllowUnsafeBlocks option, 962
Alternative statements for if
statements, 142
Ampersands (&)
address operator, 965
bitwise operators, 164
compound assignment, 167
logical operators, 152
AND operations
logical operators, 152
Angle brackets (<>)
generics, 540
XML, 33
Anonymous methods, 600
lambda expressions as replacement for, 587–588
Anonymous types
collection initializers, 702–703
generating, 702
type safety and immutability, 700–701
Any()
operator, 672
APIs (application programming interfaces)
documentation, 770
as frameworks, 40
wrapper calls, 959
AppDomain.CurrentDomain
class
exceptions, 514
process exits, 506
AppDomains for unhandled exceptions, 841–843
Append()
method, 69
AppendFormat()
method, 69
Applicable calls, 238
ApplicationException
type, 514
__arglist
keyword, 17
args
parameter for Main()
, 18–19
ArgumentException
type, 523
description, 247
nameof
operator, 514
properties, 285
ArgumentNullException
type, 513–514
description, 247
properties, 285
ArgumentOutOfRangeException
type, 513–514
Arguments
generics, 540
passed by value, 217
passing methods as, 590–592, 596
Arithmetic operations, characters in, 127–128
ArithmeticException
type, 248
Arity
type parameters, 550
Array accessors, 106
Arrays
assigning, 100
collection conversion to, 731
declaring, 98–99, 101–102, 108–109
forward accessing, 100
instantiating and assigning, 102–106
null-conditional operators, 159
overview, 99
redimensioning, 114
reverse accessing, 100
unsafe covariance, 580
ArrayTypeMismatchException
type, 248
ASP.NET, 977
AsParallel()
operator, 670, 906–907, 911
AspNetSynchronizationContext
type, 889
Assemblies
APIs, 40
boundaries, 479
CIL, 34
constants, 324
extensions, 11
AssemblyCopyrightAttribute
, 787
AssemblyFileVersionAttribute
, 787
AssemblyVersionAttribute
, 786–787
Assert()
method, 130
Assigning
nulls to references, 71
nulls to strings, 70
Assignment operators
associativity, 125
overriding, 468
Associations
data with static members, 314
with instance fields, 263
Associativity of operators, 124–125
Asterisks (*)
comments, 32
compound assignment, 132
indirection operators, 968
multiplication, 123
pointers, 963
precedence, 124
Async()
method, 875
async
operator, 861–867, 890–891
async
return types, 869–870, 877–880
AsyncEnumberable
class, 875–877
Asynchronous invocation, 818
Asynchronous methods return types, 877–881
Asynchronous pattern. See Task-based Asynchronous Pattern (TAP)
Asynchronous tasks
AsyncState
property, 828
At signs (@)
verbatim strings, 60
Atomic operations in multithreading, 819–820
AttachedToParent
task continuation option, 832
Attributes
description, 769
enum
, 443
vs. interfaces, 415
predefined, 797
System.ConditionalAttribute
, 797–799
System.ObsoleteAttribute
, 799–800
AttributeTargets
flag, 794, 799
AttributeUsageAttribute
class, 793–795, 797
Automatically implemented properties
read-only, 287, 305–306, 325–326
AutoResetEvent
event, 937
Average()
function, 693
await
operator
task-based asynchronous pattern, 861–867, 890–891
escape sequence, 58
Backslashes ()
as literals, 60
Backspace escape sequence, 58
Base Class Library (BCL)
Base class overriding
constructor invocation, 355–356
overview, 346
Base classes
derived object conversion to, 339
protected member access in, 344
Base types
casting between derived types, 339–340
description, 336
BCL (Base Class Library)
Binary expression trees, 618–619
Binary operators
associativity, 125
null-coalescing, 157
relational and equality, 150–151
Binary values
floating-point, 47
literals, 53
shift operators, 163
BinaryExpression
expression trees, 623
BinarySearch()
method
list searches, 736
BinaryTree<T>
class
index operators, 152
parameters, 572
Binding
extension methods, 412
metadata, 992
Bitwise operators
compound assignment, 167
Block statements. See Code blocks
BlockingCollection<T>
class, 938–939
Boolean (bool
) type
array initial values, 104
conversions, 75
flow control, 149
lambdas, 593
relational and equality operators, 150–151
Boolean expressions for if
statements, 142
Boolean operators
Bounds
floating-point types, 131
Boxing
generics for, 543
in loops, 448
Brand casing for namespaces, 482
Break()
method, 905
break
statements
lambda expressions, 606
overview, 141
yield break
, 764
Breaking parallel loops, 904–905
Brittle base class problem, 349–351
Buffer overflows
managed execution, 986
unsafe code, 962
byte
type, 46
C language and C# syntax similarities, 2–3
C++ language vs. C#
Boolean conversions, 75
delete
operator, 262
deterministic destruction, 502, 983
equality checks, 150
global methods, 204
global variables and functions, 311
header files, 208
implicit overriding, 347
increment and decrement operators, 136
local variable scope, 149
Main()
, 19
methods called during construction, 348–349
multiple inheritance, 345
operand evaluation, 126
operator-only statements, 123
pointer declarations, 964
preprocessor directives, 186
pure virtual functions, 361
short
type, 47
string concatenation, 61
structs, 427
switch
statements, 179
Variant and var
, 90
Calculated properties, 287–289
Call sites, 217
Call stacks for methods, 216–217
Callback functions, 587
CallerMemberName
parameter attribute, 782
Calling
collection initializers, 297–298
camelCase
description, 16
parameter names, 205, 268, 300
property names, 282
tuples, 95
"can do" relationships, 377–378
Cancel()
method
parallel iterations, 903
PLINQ queries, 911
Canceling
CancellationToken
class
asynchronous methods, 885
PLINQ queries, 911
CancellationToken
property, 904
CancellationTokenSource
class, 845–846, 903, 911
Capture()
method, 517
Captured outer variables, 611–612
Carets (^)
bitwise operators, 164
compound assignment, 167
index from end operator, 99, 107, 108, 110, 112, 118
logical operators, 152
Carriage returns
escape sequence, 58
newlines, 66
Cartesian products
inner joins, 684
query expressions, 723
Case labels
goto
statements, 185
Case sensitivity
C++ similarity, 3
importance, 2
literal suffixes, 52
Casing
local variables, 24
cast
operator and casting
base and derived types, 339–340
defining, 341
implicit conversions, 76
in inheritance chains, 340
Catch blocks
rethrowing exceptions, 251
Catching exceptions, 241–242, 514–516, 518–519
cells
member in arrays, 115
Central processing units (CPUs)
description, 815
PLINQ queries, 670
Centralizing constructor initializers, 301–302
Chains
circular, 930
delegates, 633–634, 637–638, 640
iterators, 762
null-coalescing operator, 158
queries, 722
Characters (char
) types
arithmetic operations, 127–128
array initial values, 104
Checked conversions, 73–75, 528–530
checked
keyword, 73–75, 529–530
CheckForOverflowUnderflow
property, 529
Church, Alonzo, 608
CIL. See Common Intermediate Language (CIL)
Circular wait conditions in deadlocks, 930
Class definitions
description, 17
guidelines, 17
class
keyword, 259
Classes
associated data, 314
concrete, 357
constructors. See Constructors
defined, 260
encapsulation, 261–262, 323–326
files for storing and loading, 270–273
inextensible, 320
inheritance. See Inheritance
interfaces. See Interfaces
members, 262
multiple iterators in, 766–767
object-oriented programming, 256–259
properties. See Properties
sealed, 345
static members. See Static members
vs. structs, 763
CLI. See Common Language Infrastructure (CLI)
Clock speeds, 813
Close()
method, 497
Closed over outer variables, 611–612
Closures, 614
CLR (Common Language Runtime)
CLS (Common Language Specification)
description, 994
libraries, 35
metadata, 991
CLSCompliant
attribute, 991
CLU language, 754
Clusters, 754
Code access security, 35
Code blocks
Code editors for preprocessor directives, 191–193
Code readability. See Readability
Cold tasks, 825
Collections
foreach
loops, 174–175, 661–662
initializers, 297–298, 654–657, 702–703
iterators. See Iterators
join operations. See Join operations
linked lists, 749
null values, 753
queues, 748
shared states, 660
stacks, 747
standard query operators. See Standard query operators
thread synchronization, 938–939
Collisions, name, 198
Colons (:)
conditional operators, 154–155
constraints, 561
constructors, 301
derived classes, 336
hexadecimal format, 54
labels, 185
COM threading model, 945
Combine()
method
delegates, 558–559, 634, 650–651
hash codes, 455
parameters, 217–218, 220, 226–229
COMException
type, 514
Command-line arguments, 19, 214–216
CommandLineInfo
class, 773–779
CommandLineRequiredAttribute
, 797
CommandLineSwitchAliasAttribute
, 797
CommandLineUtils
package, 773n
Commas (,)
attributes, 787
constraints, 561
enums, 447
for
loops, 173
interfaces, 384
methods, 201
parameters, 205
variable declarations, 23, 499
Comments
guidelines, 33
Common Intermediate Language (CIL)
assemblies, 34
description, 994
general catch blocks, 519
generics representation, 581–582
ILDASM, 36
indexers, 751
outer variable implementation, 613–614
Common Language Infrastructure (CLI)
Base Class Library, 979
CLS, 991
CTS, 990
encapsulation, 985
Microsoft .NET Framework, 975–977
namespaces, 482
.NET Native feature, 993
.NET Standard version, 978–979
platform portability, 985
type safety, 984
Xamarin compiler, 978
Common Language Runtime (CLR)
Common Language Specification (CLS)
description, 994
libraries, 35
metadata, 991
Common Type System (CTS), 34, 990, 994
Compacting objects in garbage collection, 490
CompareExchange()
method, 926–927
CompareTo()
method
Comparing
compare/exchange pattern, 926–927
Comparison operators
pointers, 969
Compatibility between enum types, 440–441
Compilation
ahead of time, 993
disassembling, 36
CompilerGeneratedAttribute
, 293
Complement operator (~), 167
Complexity of asynchronous requests, 859–861
ComponentModel
class, 953
Components in compilation, 980
Composite formatting
description, 29
patterns, 65
strings, 127
Compound assignment
bitwise, 167
mathematical operators, 132
overriding, 468
Compress()
method, 379
Concat()
method for strings, 62–63
Concat()
operator for queries, 693
Concatenating strings, 61–63, 126–127
Concrete classes, 357
Concurrent collection classes, 938–939
Concurrent operations, 817–818
ConcurrentBag<T>
class, 939
ConcurrentDictionary<TKey, TValue>
class, 939
ConcurrentQueue<T>
class, 939
ConcurrentStack<T>
class, 939
Conditional clauses in catch blocks, 516
Conditional operators
null. See Null-conditional operator
overriding, 468
ConditionalExpression
expression trees, 623
Conditions
for
loops, 172
if
statements, 142
Consequence statements in if
statements, 142
Console
string methods, 62
const
keyword
ConstantExpression
expression trees, 623
Constants
expressions and locals, 137–138
switch
statements, 177
Constraints
notnull, 560
Constructed struct
types, 560
Constructors
collection initializers, 297–298
finalizers, 298
generics, 547
methods called during, 348–349
non-nullable reference type properties, 303–306
overview, 293
propagating exceptions from, 507
structs, 424
Contains()
method
list searches, 736
stack searches, 747
ContainsGenericParameters
property, 779–780
ContainsKey()
method, 741
ContainsValue()
method, 741
Context switches, 137, 817–820, 850
Continuation of tasks, 829–836
continue
statements
lambda expressions, 606
overview, 140
switch
statements, 177
ContinueWith()
method
asynchronous requests, 859
synchronization context, 888–889
tasks, 829–831, 834–835, 839–840
Contravariance
delegates, 609
Control flow. See Flow control
Conversions
to binary representation, 165–167
Boolean type, 75
casts. See cast
operator and casting
checked and unchecked, 73–75, 528–530
collections to arrays, 731
covariant, 574
dynamic objects, 803
implementing classes and interfaces, 390
overview, 72
type safety, 35
Cooperative cancellation, 843–847
Copying
arrays, 115
null values, 85
CopyTo()
method
Core .NET frameworks, 39
Count()
method
description, 693
index-based collection, 412
Count
property for collections, 730–731
CountOccurrencesAsync()
method, 860–861, 864–866
Covariance
in arrays, 580
delegates, 609
CPUs (central processing units)
description, 815
PLINQ queries, 670
Create()
method, 551
Cryptographer
class, 874
.cs
file extension, 9
CTS (Common Type System), 34, 990, 994
Curly braces ({})
classes, 259
code formatting, 22
collection initializers, 297, 655–656
lambda expressions, 603
methods, 18
namespaces, 482
object initializers, 296
pattern matching, 370
properties, 278
string interpolation, 29, 61–62, 66
switch
statements, 20
type definitions, 17
use of, 19
Current
property for iterators, 764
CurrentDomain
class
exceptions, 514
process exits, 506
CurrentId
property for asynchronous tasks, 828
Data namespace, 199
Data persistence, files for, 270–273
Data types. See Types
DataBinder
class, 771
Deadlocks
Debug()
method, 799
DEBUG
preprocessor identifier, 799
Debugging
preprocessor directives for, 188
Decimal type, 49
Declaration spaces in code blocks, 147–149
Declaring
arrays, 98–99, 101–102, 108–109
await using
statement, 874–875
class type constraints, 557–558
constants, 323
deconstructors, 311
interface constraints, 556–557
out variables, 222
parameters, 205
read-only automatically implemented properties, 325–326
static fields, 312
types from unmanaged structs, 952–953
Decrement()
method, 137, 927–928
Decrement operators
description, 133
thread-safe, 137
Default interface members
vs. extension methods, 411–413
default
operator for generics, 547–549
default sections in switch
statements, 179, 184
Default values
structs, 424
DefaultIfEmpty()
method, 688–689
Deferred execution
Defining
attributes, 786
calculated properties, 288–289
generic classes, 542
generic constructors, 547
iterators, 754
preprocessor symbols, 189
stacks, 537
Delay()
method, 944
delegate
keyword, 592
Delegates
deferred execution, 715
function pointers to, 960
method returns and pass-by-reference, 640
null-conditional operators, 161
process exits, 506
publish-subscribe pattern operators, 633–634
statement lambdas for, 601–604
tasks, 824
delete
operator, 262
Deleting files, 496
Delimited comments, 32
DenyChildAttach
task continuation option, 832
Dependencies in libraries, 10
Dequeue()
method, 748
Dereferencing
description, 83
null-conditional operator for, 513
null values, 87
Derivation
casting between base and derived types, 339–340
extension methods, 344
private
access modifier, 341–342
protected
access modifier, 342–344
sealed classes, 345
single inheritance, 345
Derived members, 335
Derived objects converted to base class, 339
Derived types
casting between base types, 339–340
description, 336
DescriptionAttribute
, 786
Deterministic destruction, 502, 983
Deterministic finalization, 496–500
Deterministic resource cleanup, 262
Diagnostics
class
debugging with, 799
notifications, 885
processes, 815
Diagramming interfaces, 395–396
Dictionaries
collection initializers, 656
thread synchronization, 939
Dictionary<TKey, TValue>
class
collections, 658
Dimensions for arrays, 102–106, 114
Directives
dynamic, 803
preprocessor. See Preprocessor directives
Directories, copying, 316, 321–322
DirectoryInfo
class
extension methods, 321
inner joins, 682
DirectoryInfoExtension
class, 315–316, 321–322
DisallowNull
attribute, 307
Disambiguating multiple Main()
methods, 214–216
Disassembling programs, 36
Discards
out
parameters, 222
tuples, 96
DispatcherTimer
class, 944
Disposability of tasks, 849
Dispose()
method
collections, 661
resource cleanup, 495, 497–499
DisposeAsync()
method, 874–875
Distinct members in query expressions, 723–724
Distinct()
operator
description, 693
Division
binary operator, 123
compound assignment, 132
shift operators, 164
by zeros, 131
DLLs (dynamic link libraries), 10–11
do/while
loops
overview, 140
Documentation
reflection, 770
Dollar signs ($) for string interpolation, 28, 61–62
DotGNU Portable.NET compiler, 976
Dotnet CLI
code building and executing, 12
project and library references, 474
Double quotes (")
double
type
special characteristics, 128–129
DownloadData()
method, 856
DownloadDataTaskAsync()
method, 858–860, 865
DownloadString()
method, 856
Drawing
class, 199
Duck typing, 662
Duplicating interfaces, 545–546
dynamic data type principles and behaviors, 803–805
Dynamic invocation
Dynamic link libraries (DLLs), 10–11
Dynamic programming
description, 769
principles and behaviors, 803–805
vs. static compilation, 807–808
Editors
preprocessor directives, 191–193
Visual Studio 2019. See Visual Studio 2019
else
clauses, 142
Empty collections, 753
Empty
property for events, 645
Empty strings, 70
Encapsulation
CLI, 985
object-oriented programming, 257
with protected interface members, 406–411
EncryptAsync()
method, 874
#endif
directive, 188
EndsWith()
method, 63
Enqueue()
method, 748
Enter()
method with monitors, 432, 918–920, 922–924
enum values
parsing, 78
Enumerable
class
delegates, 621
filters, 667
parallel queries, 907
query expressions, 714
standard query operators, 663
Enumerator patterns for iterators, 754–755
Environment
class
command-line arguments, 19, 216
newlines, 66
thread synchronization, 933
Equality
C# vs. C++, 150
EqualityComparer<T>
class, 463, 743
Equals()
method
description, 364
with GetHashCode()
, 453–454, 744
null values, 87
reflection, 427
Equals signs (=)
compound assignment, 132, 167, 468
delegates, 632–634, 641–642, 650
equality operator, 55
null checks, 86
null-coalescing operator, 157–158
pointers, 969
precedence, 124
properties, 278
relational and equality operators, 150–151
Equi-joins, 688
#error
directive, 187, 189–190
Error handling. See also Exceptions
exception class inheritance, 246–248
publish-subscribe pattern, 637–640
Errors
preprocessor directives for, 186–191
EssentialCSharp.sln
file, 12
Evaluation of operators, 125
EventHandler<T>
class, 644, 647–648, 650–651, 887
Events
generics and delegates, 647–648
overview, 625
publication encapsulation, 642–643
publish-subscribe pattern. See Publish-subscribe pattern
purpose, 641
subscription encapsulation, 641–642
thread synchronization, 928–929
Exception conditions, 516
Exceptional continuation, 829
ExceptionDispatchInfo
class
asynchronous requests, 860
Exceptions
catch blocks, 248–249, 514–516, 518–519
propagating from constructors, 507
publish-subscribe pattern, 637–640
rethrowing, 517–518, 522–523, 527–530
serializable, 526
ExceptionServices
class, 517
Exchange()
method, 927
Exclamation points (!)
equality operators, 55
generics, 582
logical operators, 153
null-forgiving operators, 160–161
pointers, 969
Excluding code, preprocessor directives for, 188
Exclusive OR (XOR) operators
Executables, stand-alone, 11–12
ExecuteSynchronously
task continuation option, 833
Execution time, 35
ExecutionEngineException
type, 514
Exit()
method with monitors, 432, 918–920, 923–924
Expanded form for parameters, 227
Explicit casts
base and derived types, 339
Explicit deterministic resource cleanup, 262
Explicit member implementation, 386–390
Exponential notation, 52
Expression bodied members
declaring, 208
properties, 279
Expression trees
deferred execution, 715
description, 616
Expressions
lambda. See Lambda expressions
query. See Query expressions
Extended Application Markup Language (XAML), 977
Extensible Markup Language. See XML (Extensible Markup Language)
Extension methods
vs. default interface members, 411–413
derivation, 344
Extensions, file, 9
External methods and functions
f
escape sequence, 58
f-reachable (finalization) queues, 298, 500–501
Factory interfaces for constructor constraints, 564
FailFast()
method, 514
Failure type, 514
false
operator, overriding, 468–470
Fat arrow notation (=>) for lambda expressions, 608
FCL (Framework Class Library), 979, 993–994
Fields
instance. See Instance fields
strings, 66
thread synchronization, 926
FIFO (first in, first out) collections, 748
FileAttributes
class, 443
FileInfo
class
inner joins, 682
query expressions, 710
Files
deleting, 496
extensions, 9
Java language vs. C#, 10
project, 10
storing and loading with, 270–273
FileStream
class
finalizers, 495
IAsyncDisposable
, 874
storing and loading files, 270–273
ToString()
, 452
Filters
Browse, 477
collections, 593–594, 666–667, 672–676
query expressions, 706, 715–716
Finalization, deterministic, 496–500
finalization (f-reachable) queues, 298, 500–501
finalize()
method, 364
Finalizers
constructors, 298
generics, 547
resource cleanup, 493–496, 500–501
finally
blocks in error trapping, 244–246
First in, first out (FIFO) collections, 748
fixed
statement for pointers, 966–967
FlagsAttribute
Flatten()
method, 860
Flattening sequences in query expressions, 722–723
float
type
special characteristics, 128–129
Floating-point types
special characteristics, 128–129
Flow control
description, 121
preprocessor directives, 186–193
task continuation, 829
threads, 816
while
and do/while
loops, 168–170
for
loops
Forcing resource cleanup, 503–507
foreach
loops
enumerator patterns, 754
IEnumerable<T>
, 658–659, 662–663
Form feeds escape sequence, 58
Formal parameter lists, 205
Format items, 29
FormatException
type, 244, 247
FormatMessage()
method, 953
Formatting
hexadecimal format, 54
with string interpolation, 28
Forward accessing arrays, 100
Forward slashes (/)
command-line option, 783
compound assignment, 132
precedence, 124
XML elements, 33
Fragile base class problem, 349–351
Framework Class Library (FCL), 979, 993–994
Framework Design Guidelines, 15
Frameworks
APIs, 40
.NET. See .NET frameworks
from
keyword in query expressions, 707–709, 714, 722–723
FromCurrentSynchronizationContext()
method, 887
Full outer joins, 679
Fully qualified method names, 198
Functions
pointers to delegates, 960
Garbage collection
managed execution, 35
Microsoft .NET framework, 489–491
objects, 261
overview, 489
resource cleanup. See Resource cleanup
GC
class
finalization, 500
finalizers, 496
garbage collection timing, 490
General catch blocks, 248–249, 518–520
Generics
constraints. See Constraints
constructors, 547
covariance and contravariance, 573–580
defining, 542
delegates, 609
finalizers, 547
interfaces and structs, 544–546
linked lists, 749
overview, 533
type parameters, 308–309, 542–545, 549–552, 780–781
get
keyword for properties, 278–279
GetAsyncEnumerator()
method, 872–873
GetCommandLineArgs()
method, 216
GetCustomAttributes()
method, 788–790
GetEnumerator()
method
duck typing, 662
purpose, 660
standard query operators, 663
GetFiles()
method
directories, 321
inner joins, 682
GetGenericArguments()
method, 780
GetHashCode()
method
description, 364
value types, 427
GetLastError()
method, 953
GetLength()
method, 114
GetMethods()
method, 771
GetProperties()
method, 771–772
GetResult()
method, 881
getters
GetType()
method
description, 364
null values, 87
objects, 462
GetValue()
method, 777
GhostDoc tool, 489
Global methods, 204
Global variables and functions, C# vs. C++ and Visual Basic, 311
"goes to" operator, 208
goto
statements
lambda expressions, 606
overview, 141
Graphs for expression trees, 618–619
Greater than signs (>)
generics, 540
pointers, 969
referent member access, 970
relational operators, 150
XML, 33
group
clauses in query expressions, 707, 720–722
group by
clause, 719
Grouping query expressions, 718–721
GroupJoin()
method
Handle()
method
asynchronous requests, 860
task exceptions, 839
Handlers for process exits, 506
Hardcoding values, 50
HasFlags()
method, 444
Hash codes and tables
dictionaries, 741
Hash symbols (#) for preprocessor directives, 186
Hat operator (^) for arrays, 107–108
Header files, 208
Heap
boxing, 428
new
operator, 262
HelloWorld.dll file, 10
HelloWorld program
Hexadecimal numbers
formatting numbers as, 54
Unicode characters, 58
HideScheduler
task continuation option, 833
High-latency operations
Hill climbing, 899
Hold and wait conditions in deadlocks, 930
Hooking up publishers and subscribers, 628–629
Horizontal tabs escape sequence, 58
Hot tasks, 825
Hungarian notation, 16
Hyper-Threading, 815
Hyphens (-). See Minus signs (-)
I/O-bound operations
latency, 814
performance considerations, 818–820
IAsyncDisposable
interface, 874–875
IAsyncEnumerable<T>
interface
IAsyncEnumerator<string>
interface, 877, 881
ICollection<T>
interface
collection initializers, 654–655
IComparable<string>
interface, 734
IComparable<T>
interface, 554–557, 572
IComparer<T>
interface, 734–735
Id
property for asynchronous tasks, 828
IDE (integrated development environment)
debugging support, 8
Visual Studio 2019, 6
Identifiers
guidelines, 16
keywords as, 17
IDictionary<TKey, TValue>
interface, 728–730
IDisposable
interface
resource cleanup, 497–501, 661–662
tasks, 849
IDynamicMetaObjectProvider
interface, 808
IEnumerable<T>
interface
filters, 667
PLINQ queries, 911
projections, 669
query expressions, 708–709, 714
standard query operators, 663
task-based asynchronous pattern, 877
yield
statement, 767
IEnumerator<T>
interface
yield
statement, 767
IEqualityComparer<T>
interface, 743–744
IEquatable<T>
interface, 463
if
statements
Boolean expressions, 149
continue
statement replacement, 183–184
overview, 139
switch
statements for, 178
working with, 142
IFileCompression
interface, 379
ILDASM (IL Disassembler), 36–37
IList<TKey>
interface, 746
IList<TValue>
interface, 746
Immutability
delegates, 598
value types, 424
Immutable library, 939
Implementing class conversions with interfaces, 390
Implicit conversions
base and derived types, 339
Implicit deterministic resource cleanup, 262
Implicit member implementation, 386–390
implicit
operator for types, 75–76
Implicitly typed local variables, 89–90
import
directive, 210
in
parameters, 223
Including code, preprocessor directives for, 188
Increment()
method, 137, 927–928
Increment operators
description, 133
thread-safe, 137
Indenting code
Index operator
variable parameters, 752
Index from end operator, 99, 107, 108, 110, 112, 118
Index
type, 112
IndexerNameAttribute
, 751
Indexes
list searches, 736
sorted collections, 746
IndexOf()
method, 736
IndexOutOfRangeException
type, 247
Indirection operators for pointers, 968–969
Inequality
Inextensible classes, 320
Inferences for generic methods, 569–571
Infinite recursion errors, 231
Infinity value, 131
Infix notation for binary operators, 123
Information hiding in encapsulation, 274–276
Inheritance
base class overriding. See Base class overriding
casting in, 340
derivation. See Derivation
System.Object
class in, 363–365
value types, 427
Initial section in for
loops, 172–173
Initializers
Initializing
anonymous type arrays, 702–703
dictionaries, 656
fields, 548
loop counters values, 170
static members, 312–313, 317–318
Inner classes, 328
Inner joins
description, 679
one-to-many relationships, 686–688
InnerException
property, 522, 525, 527
InnerExceptions
property
aggregate exceptions, 838, 908
asynchronous requests, 860
error handling, 640
parallel loops, 901
tasks, 838
INotifyCompletion
interface, 881
INotifyPropertyChanged
interface, 782
Insert()
method, 69
Inserting dictionary items, 740–741
Instance fields
Instance members
strings, 62
Instantiation
defined, 19
Integers and int
type
characters, 127
conversions, 72
default, 50
description, 23
enums, 439
Integrated development environment (IDE)
debugging support, 8
Visual Studio 2019, 6
IntelliSense feature, 708
Interfaces
vs. attributes, 415
converting between implementing classes, 390
extension methods, 394–395, 411–413
implementation, 377–378, 384–390
overview, 377
value types, 427
versioning. See Versioning
Interlocked
class
increment and decrement operators, 137
internal
access modifier
description, 481
interface refactoring, 402
Interoperability. See Platform interoperability
InteropServices
class
unmanaged exceptions, 519
Interpolation of strings, 28–30, 61–62
Intersect()
operator, 693
into
clause in query expressions, 721–722
InvalidAddressException
type, 523
InvalidCastException
type
description, 247
generics, 543
using, 472
InvalidOperationException
type
collections, 663
description, 247
null values, 87
tasks, 838
wrapped exceptions, 527
Invocation
base class constructors, 355–356
referenced packages and projects, 477–479
using
statement, 499
Invoke()
method
delegates, 630
dynamic invocation, 777
events, 161
IOrderedEnumerable<T>
interface, 677
IProducerConsumerCollection<T>
interface, 939
IQueryable<T>
interface
query expressions, 708
"is a" relationships
abstract members, 361
classes, 388
derivation forms in, 339
"is a kind of" relationships, 257–258, 336
is
operator
pattern matching example, 156–157
pattern matching overview, 365–371
positional pattern matching, 369
recursive pattern matching, 370–371
tuples, 368
type, var
, and const
pattern matching, 366–368
is { }
property pattern, 156–157
IsCancellationRequested
property, 846
IsCompleted
property
multithreading, 828
parallel loops, 905
IsDefined()
method, 445
ISerializable
interface, 526
IsGenericType
property, 780
IsInvalid
member, 956
Iterations
loops, 170
parallel. See Parallel iterations
Iterators
defining, 754
syntax, 755
Jagged arrays
defining, 106
length, 110
Java language vs. C#
exception specifiers, 518
filenames, 10
implicit overriding, 347
import directive, 210
inner classes, 328
Main()
, 19
virtual methods, 346
JIT (just-in-time) compiler and jitting
CIL, 980
description, 34
thread synchronization, 920
Join()
method
threads, 914
Join operations
Jump statements
lambda expressions, 606
Just-in-time (JIT) compiler and jitting
CIL, 980
description, 34
thread synchronization, 920
KeyNotFoundException
type, 741
Keys
dictionaries, 728–730, 740–741
sorted collections, 746
Keys
property, 746
KeyValuePair<TKey, TValue>
class, 741
Keywords
contextual, 766
as identifiers, 17
list of, 14
types, 47
Labels for switch
statements, 177, 185
Lambda calculus, 608
Lambda expressions
deferred execution, 674
filters, 715
overview, 587–588, 600–601, 604
predicates, 593
purpose, 608
LambdaExpression
expression trees, 623
Language Integrated Query (LINQ)
delegates, 620
extension methods, 395
with IAsyncEnumerable
, 875–877
parallel queries, 670–671, 905–911
query expressions. See Query expressions
Language interoperability, 35
Last in, first out (LIFO) collections, 747
LastIndexOf()
method, 736
Late binding with metadata, 992
Latency
description, 814
LazyCancellation
task continuation option, 834
Leaf asynchronous task-returning method, 883–887
Left-associative operators, 125
Left outer joins, 679
Length
Length
property, 66
Less than signs (<)
generics, 540
pointers, 969
relational operators, 150
XML, 33
Libraries
BCL. See Base Class Library (BCL)
creating, 473
dependencies, 10
TPL. See Task Parallel Library (TPL)
Lifetime of captured outer variables, 612
LIFO (last in, first out) collections, 747
Line-based statements in Visual Basic vs C#, 20
Line feeds
newlines, 66
Line numbers, preprocessor directives for, 191
Linked lists, 749
LinkedList<T>
class, 749
LinkedListNode<T>
class, 749
LINQ. See Language Integrated Query (LINQ)
List<T>
class
Listeners for events, 627, 835–836
Lists
linked, 749
Literal values
characters, 57
Load()
method, 273
Loading
Local variables
thread synchronization, 917–918
types, 23
working with, 25
Localized applications, Unicode standard for, 56
lock
keyword
thread synchronization, 920–925
Locks
thread synchronization, 920–925, 931
Logical operators
overriding, 468
Lollipops, 395
long
type
characteristics, 46
conversions, 72
LongRunning
task continuation option
delays, 849
description, 832
TPL performance, 900
Loop variables in lambda expressions, 614–616
Loops
LowestBreakIteration
property, 905
Machine code, compilation to, 34–35, 979–981
Main()
method
async, 867
Java vs. C#, 19
return values and parameters, 214–216
__makeref
keyword, 17
Managed code, 34
ManualResetEvent
class, 934–937
ManualResetEventSlim
class, 934–937
Many-to-many relationships in join operations, 679–680
Masks, logical operators for, 165
Matching caller variables with parameters, 218
Max()
function, 693
MaxDegreeOfParallelism
property, 904
MaybeNullWhen
attribute, 307
Me
keyword, 268
Mechanism relationships, 388
Members
base class overriding, 353–355
class variables, 262
classes, 262
dynamic invocation, 773–779, 781–782
explicit and implicit implementation, 386–390
static. See Static members
MemberwiseClone()
method, 364
Memory
boxing, 428
finalizers, 495
generics, 543
multithreading complexity, 821
objects, 261
Metadata
CLI, 35
XML, 33
Method groups for delegates, 596
Method invocations, query expressions as, 724–725
MethodCallExpression
expression trees, 623
MethodImplAttribute
, 925
MethodImplOptions
class, 925
MethodInfo
class
delegates, 598
dynamic invocation, 777
reflection, 788
Methods
anonymous, 600, 606–608, 610–611
arguments, 201
attributes, 799
called during construction, 348–349
constructors. See Constructors
expression bodied, 208
extension, 321–322, 344, 394–395, 411–413
interface refactoring, 401
names, 201
parameters. See Parameters
passing as arguments, 590–592, 596
publish-subscribe pattern, 640
scope, 201
structs, 424
syntax, 18
Microsoft .NET Framework
assemblies, 40
description, 39
Microsoft Silverlight compiler, 976
Min()
function, 693
Minus signs (-)
compound assignment, 132
decrement operator, 133
identifier names, 16
precedence, 124
referent member access, 970
subtraction, 123
Modules
dependencies, 992
Monitor
class
locks, 432
thread synchronization, 918–920, 923–924
Mono compiler, 976
Mono .NET frameworks, 39
Move()
method, 321
MoveNext()
method
duck typing, 662
MoveNextAsync()
method, 874
MTAs (multithreaded apartments), 945
Multicast delegates
description, 625
publish-subscribe pattern. See Publish-subscribe pattern
MulticastDelegate
class
Multidimensional arrays, 102–106, 108
Multiple inheritance
C++, 345
interfaces, 393
Multiple interfaces for single classes, 545–546
Multiple Main()
methods, 214–216
Multiple .NET frameworks, 39–43
Multiple searches in lists, 737–738
Multiple selection for query expressions, 722–723
Multiple threads synchronization. See Thread synchronization
Multiple type parameters in generics, 549–551
Multiplication
binary operator, 123
compound assignment, 132
shift operator, 164
Multithreaded apartments (MTAs), 945
Multithreading
asynchronous tasks. See Asynchronous tasks
description, 816
disposability of tasks, 849
memory model complexity, 821
performance considerations, 818–819
Mutable value types, 434
Mutual exclusion in deadlocks, 930
new lines, 66
Name/value pairs for dictionaries, 656, 738, 741
Named parameters
changing names of, 237
nameof
operator
arguments, 513
properties, 285
Names
class definitions, 17
collisions, 198
constant values, 137
constructor parameters, 300
constructors, 294
enums, 439
indexers, 751
local variables, 24
tuples, 95
type parameters, 544
variables, 418
Namespaces
nesting, 483
using
directive, 64–65, 209–211
NaN
(Not a Number) value, 131
Native code, 34
NDoc tool, 489
Negation operator (!), 153
Negative infinity value, 131
Negative numbers notation, 163
Negative zero value, 132
Nested items
.NET Compact Framework, 976
.NET frameworks
description, 993
garbage collection, 489–491, 983–984
overview, 3
.NET Micro Framework, 976
Net namespace, 483
.NET Native feature, 993
.NET Standard version, 978–979
new
modifier in base class overriding, 349–353
new
operator
Newlines
preprocessor directives, 186
variations, 66
NGEN tool, 980
No preemption condition in deadlocks, 930
NodeType
property expression trees, 623
Non-nullable reference type properties, 303–306
None
task continuation option, 831
Normal continuation, 829
Normal form for parameters, 227
Normalized data, 682
Not a Number (NaN
) value, 131
NOT operators
logical, 153
Notifications for thread synchronization, 928–929
NotImplementedException
type, 248
NotNull
attribute, 307
notnull constraints, 560
NotNullIfNotNull
attribute, 307–308
NotNullWhen
attribute, 307–308
NotOnCanceled
task continuation option, 833
NotOnFaulted
task continuation option, 832
NotOnRanToCompletion
task continuation option, 832
nowarn
preprocessor directive option, 190–191
NuGet packages
referencing, 473
Null character escape sequence, 57
Null-coalescing operator, 157–160
Null-conditional operator
dereferencing operations, 513
thread synchronization, 928
Null-forgiving operator (!), 160–161, 634
null
references, dereferencing, 85
null
values
collections, 753
dereferencing, 87
publish-subscribe pattern, 630–632
#nullable
directive, 88, 187, 193
nullable
modifier
reference types, 71
strings, 70
Nullable reference types
default values, 548
nullable
modifier, 84
preprocessor directives, 193
Nullable values
array initial values, 104
default values, 548
description, 86
struct constraints, 561
Nullable<T>
type, 87, 308, 561
NullReferenceException
type
delegates, 644
dereferencing null values, 85, 87, 513
description, 248
reference type nullability, 88
thread synchronization, 928
Numeric types
decimal, 49
Object
class
Object-oriented programming
encapsulation, 257
polymorphism, 259
Objects. See also Classes
associated data, 314
CTS, 990
defined, 260
identity vs. equality, 456–460
ObsoleteAttribute
, 797, 799–800
OfType<T>()
operator, 693
One-to-many relationships
OnlyOnCanceled
task continuation option, 832
OnlyOnFaulted
task continuation option, 833
OnlyOnRanToCompletion
task continuation option, 833
Operands
description, 122
evaluation, 126
Operational polymorphism, 232
OperationCanceledException
type, 908, 911
operator
keyword, 466
Operators
characters in arithmetic operations, 127–128
constant expressions and locals, 137–138
description, 121
evaluation, 125
floating-point equality, 129–132
increment, 133
overview, 122
relational and equality, 150–151
special floating-point characteristics, 128–129
thread-safe, 137
OR operations
constraints, 568
OrderByDescending()
method, 678
out
parameters
conversions, 78
properties, 291
out
type parameter modifier, 575–577
Outer variables in lambda expressions, 611–616
OutOfMemoryException
type, 514, 520
Overflow, buffer
managed execution, 986
unsafe code, 962
OverflowException
type, 73, 529
Overloading
Overriding
assignment operators, 468
Base class. See Base class overriding
GetHashCode()
, 453–455, 463–464
logical operators, 468
P/Invoke. See Platform Invoke (P/Invoke)
Pair<T>
type
struct vs. class, 763
Parallel iterations
overview, 895
Parallel LINQ (PLINQ), 814
running queries, 670–671, 905–908
Parallel loops
Parallel programming, 818
ParallelEnumerable
class, 670, 906–907
ParallelLoopResult
class, 905
ParallelLoopState
class, 905
ParallelOptions
class, 904
ParallelQuery<T>
class, 911
ParameterExpression
expression trees, 623
Parameterized generic types, 539–540
Parameters
catch blocks, 516
constraints. See Constraints
declaring, 205
events, 645
extension methods, 322
finalizers, 495
generics, 542, 544–545, 549–551
in
, 223
indexers, 752
lambda expressions, 606
matching caller variables with, 218
Parentheses ()
collection initializers, 655
declaration lists, 205
lambda expressions, 603
logical operators, 152
operator precedence, 125
query expressions, 723
tuples, 92
Parse()
method
enum, 442
Partial classes
Partial interface refactoring, 405
Partial methods
description, 208
interface refactoring, 405
PascalCase
field names, 281
interfaces, 379
namespaces, 482
properties, 282
tuples, 95
type names, 17
Pass-by-reference, 640
Passed by reference variables, 220
Passed by value arguments, 217
Passing
anonymous methods, 607
arrays, 226
command-line arguments, 215
instances, 419
method return values, 202
methods as arguments, 590–592, 596
null values, 85
out
parameters, 220
read-only references, 223
variables by reference, 219
variables to methods, 197
Pattern matching
with null, 156
polymorphism, 373
positional, 369
switch
statements, 179, 371–372
tuples, 368
types, var
, and const
, 366–368
Peek()
method, 747
Percent signs (%)
compound assignment, 132
precedence, 124
remainder operation, 123
Performance
hash codes, 454
Periods (.)
fully qualified method names, 198
null-conditional operator, 158
Platform interoperability
pointers and addresses, 960–970
Platform Invoke (P/Invoke)
description, 948
external functions, 948–949, 956–958
function pointers, 960
wrappers, 959
Platform portability
CLI, 985
managed execution, 35
preprocessor directives for, 188
PLINQ. See Parallel LINQ (PLINQ)
Plus signs (+)
addition, 123
characters, 127
compound assignment, 132
increment operator, 133
precedence, 124
Pointers
function, 960
vs. ref, 951
referent member access, 970
Polyfill code, 526
Polymorphism
operational, 232
overview, 259
pattern matching, 373
with protected interface members, 406–411
Pools
temporary, 419
Pop()
method, 534–537, 747–748
Positional pattern matching, 369
Positive infinity value, 131
Positive zero value, 132
#pragma
directive, 187–188, 190–191
Precedence of operators, 124–125, 194
Precision of floating-point types, 47–48, 128–129
Predefined attributes, 797
Predefined types, 45
Predicates
filters, 715
lambdas, 593
PreferFairness
task continuation option, 832
Prefixes for hexadecimal notation, 53
Preprocessor directives
excluding and including code, 188
line numbers, 191
nullable references, 193
purpose, 186
symbols, 189
private
access modifier
description, 481
interface refactoring, 402
nested classes, 328
private internal
access modifier, 481
Private members for information hiding, 274–276
private protected
access modifier, 402–403
Procedural programming, 195
Process
class
multithreading, 815
notifications, 885
Processes, description, 815
Processor-bound latency, 814
Projections
query expressions, 706, 708–711
Projects
Properties
automatically implemented. See Automatically implemented properties
interface refactoring, 401
lazy loading, 508
nameof
operator, 285
read-only and write-only, 286–287
unallowed parameter values, 291
PropertyChanged
event, 782
PropertyInfo
class
dynamic invocation, 777
protected
access modifier
description, 481
interface refactoring, 402
protected interface members, encapsulation and polymorphism with, 406–411
protected internal
access modifier, 480–481
public
access modifier
description, 481
interface refactoring, 402
Public constants, 324
Publish-subscribe pattern
delegate invocation, 629–632, 634–636
encapsulation, 641
hooking up publishers and subscribers, 628–629
method returns and pass-by-reference, 640
multicast delegate internals, 636–637
Pulse()
method, 920
Pure virtual functions, 361
Quantums, 817
Queries, parallel, 670–671, 905–911
Query continuation clauses, 721–722
Query expressions
as method invocations, 724–725
query continuation clauses, 721–722
Queryable
class
delegates, 620
Question marks (?)
command-line option, 783
conditional operators, 154–155
null-coalescing operator, 157–158
null-conditional operators, 158–160
Queues
collections, 748
escape sequence, 58
newlines, 66
Race conditions
increment and decrement operators, 137
thread synchronization, 916
Range type, 112
Range variables in query expressions, 707–708, 721
Ranges for arrays, 101, 111–112
Read()
method
interlocks, 927
Read-only
automatically implemented property
Read-only pass by reference parameters, 223
Read-only properties
strings, 67
Read/write non-nullable reference type properties, 304–305
Readability
delegates, 594
digit separators, 52
enums, 437
generics, 543
if
statements, 183
importance, 203
indentation, 146
methods, 18
parentheses, 125
switch
statements, 179
ReadAllTextAsync()
method, 874
ReadAsync()
method, 864
ReadKey()
method, 27
ReadLine()
method
Recursion
infinite, 231
Redimensioning arrays, 114
Reentrant locks, 930
ref
parameters for properties, 291
Refactoring
ReferenceEquals()
method
description, 364
with null, 156
References and reference types
array initial values, 104
covariance, 576
default values, 548
generic instantiation, 583–584
identity vs. equality, 456–459
new
operator, 426
non-nullable properties, 303–306
Referent types
member access, 970
Reflection
description, 769
Reflection
class
delegates, 598
metadata, 772
__reftype
keyword, 17
__refvalue
keyword, 17
#region
directive, 187, 191–193
Register()
method, 846
Registration
assemblies, 989
finalization activities, 503–504
token cancellation, 846
RegularExpressions
class, 199
ReleaseHandle()
method, 956
Remainder operations
binary operator, 123
compound assignment, 132
Remove()
method
dictionary elements, 741
lists, 733
strings, 69
RemoveAt()
method, 733
Representation errors for floating-point types, 128–129
ReRegisterFinalize()
method, 507–508
Reset events for thread synchronization, 934–937
Reset()
method, 659
Resize()
method, 114
Resolution of methods, 238–239
Resource cleanup
description, 493
deterministic finalization, 262, 496–500
exception propagating from constructors, 507
garbage collection, finalization, and IDisposable, 500–501
Results, operator, 122
Rethrowing exceptions, 517–518, 522–523, 527–530
Return by reference parameters, 223–225
Return values
asynchronous void methods, 877–881
Reverse accessing arrays, 100
Reverse()
method
arrays, 112
collections, 693
Right-associative operators, 125
Right outer joins, 679
Root references in garbage collection, 490
Rounding floating-point types, 48, 128–129
Run()
method
RunContinuationsAsynchronously
task continuation option, 834
RunProcessAsync()
method, 883
Runtime
defined, 35
description, 35
purpose, 974
Runtime callable wrappers (RCWs), 945
Runtime.InteropServices.COMException
type, 514
sbyte
type, 46
Schedulers for tasks, 824, 887–889
Scope
captured outer variables, 612
methods, 201
SDK (software development kit), 3
sealed
access modifier
base class overriding, 353–354
interface refactoring, 404
sealed classes, 345
Sealed classes, 345
Searching
dictionaries, 741
Security
buffer overflows, 110
code access, 35
hash codes, 454
obfuscation, 36
select
clauses in query expressions, 707–708
Select()
method
LINQ queries, 906
outer joins, 691
Selecting into anonymous types, 698–699
SelectMany()
method
Semantic relationships, 388
Semaphore
class
thread synchronization, 934
Semicolons (;)
ending statements, 20
preprocessor directives, 189
SequenceEquals()
operator, 693
Sequences in query expressions, 722–723
Sequential invocation, 634–636
Serializable exceptions, 526
SerializableAttribute
, 526
SerializationInfo
type, 526
set
keyword for properties, 278–279
Set()
method for thread synchronization, 934
SetResult()
method, 885
setters
SetValue()
method, 777
Shared collection states, 660
Shared Source compiler, 976
Short-circuiting operators
asynchronous methods, 868
conditional, 154
logical, 152
null-coalescing, 157
null-conditional expressions, 159
short
type, 46
SignalAndWait()
method, 933
Signatures
deconstructors, 311
interfaces, 396
Significant digits in floating-point types, 48
Silverlight compiler, 976
Simultaneous multithreading, 815
Single inheritance, 345
Single-line comments, 32
Single quotes (')
characters, 57
escape sequence, 57
Single-threaded programs, 816
Software development kit (SDK), 3
Sort()
method
arrays, 112
lists, 733
SortedDictionary<TKey, TValue>
class, 745–747
Sorts
standard query operators, 676–678
Source code
editing with Visual Studio 2019, 6–8
Special floating-point characteristics, 128–129
Splitting statements across lines, 20
Square brackets ([])
indexers, 750
null-conditional operators, 158–160
Stack unwinding, 217
Stack<T>
class
StackOverflowException
type, 248, 514, 520
Stacks
collections, 747
exception handling, 521
rethrowing exceptions, 517–518
thread synchronization, 939
value types, 419
Stand-alone executables, 11–12
Standard query operators
list of, 693
Start()
method, 406–407, 826, 829
StartNew()
method, 847–849, 914
StartsWith()
method, 63
Statements
multiple on one line, 20
splitting across lines, 20
without semicolons, 20
States
collections, 660
STAThreadAttribute
, 945
Static compilation vs. dynamic programming, 807–808
Static members
associated data, 314
interface refactoring, 401
overview, 311
Stop()
method, 905
Store()
method, 270
Storing
StreamingContext
type, 526
StreamReader
class
async methods, 864
data retrieval, 273
Streams, asynchronous, 870–874
Strings
comparing, 56
description, 59
immutability, 26, 67–69, 968–970
modifying, 69
newlines, 66
nullable
modifier, 70
nullable reference types, 71
void
values, 69
Strong references in garbage collection, 491–493
StructLayoutAttribute
, 952–953
structs
vs. classes, 763
readonly, 423
Structural equality of delegates, 608–609
Structured programming, 195
Subscribers
events, 645
Subscriptions. See Publish-subscribe pattern
Subtraction
binary operator, 123
compound assignment, 132
decrement operator, 133
Suffixes
attributes, 786
numeric types, 46
Sum()
function, 693
SuppressFinalize()
method, 500–501
Surrogate pairs, 57
switch
statements
overview, 141
Symbols, preprocessor, 189
Synchronization
thread. See Thread synchronization
Synchronization context with task schedulers, 887–889
Synchronized method, 925
Synchronous delegates, 824
Syntax
iterators, 755
methods, 18
tuples, 92
type definitions, 17
System.Action
delegates, 592–594
System.ApplicationException
type, 247, 514
System.ArgumentNullException
type, 247, 285, 513–514
System.ArithmeticException
type, 248
System.Array.Reverse()
method, 112, 116–117
System.ArrayTypeMismatchException
type, 248
System.Attribute
class, 787
System.AttributeUsageAttribute
class, 793–795, 797
System.Boolean
class, 56
System.Char
class, 56
System.Collections.Generic
class
linked lists, 749
System.Collections.Generic.ICollection<T>
interface
collection initializers, 654–655
System.Collections.Generic.IEnumerable<T>
interface. See IEnumerable<T>
interface
System.Collections.Generic.IEnumerator<T>
interface, 658–662
yield
statement, 767
System.Collections.Generic.List<T>
class, 736–738
System.Collections.Generic.Stack<T>
type, 658–659
System.Collections.Generics
namespace, 199
System.Collections.IEnumerable
interface, 760
System.Collections.IEnumerator
interface, 658–662
System.Collections.Immutable
library, 939
System.Collections.Stack
class, 534–537
System.ComponentModel
class, 953
System.Console
class
output methods, 19, 28–33, 197
System.Convert
type, 76
System.Data
namespace, 199
System.Delegate
class
assignment operators, 634, 650
System.Diagnostics
class
debugging with, 799
notifications, 885
processes, 815
System.Drawing
class, 199
System.Dynamic.DynamicObject
class, 808–811
System.Dynamic.IDynamicMetaObjectProvider
interface, 808
System.Environment
class
command-line arguments, 19, 216
new lines, 66
thread synchronization, 933
System.EventArgs
class, 645–647
System.EventHandler<T>
class, 647–648, 650–651
System.Exception
type, 511–512, 514
description, 247
System.FormatException
type, 244, 247
System.Func
delegates, 592–594
System.GC
class
finalization, 500
finalizers, 496
garbage collection timing, 490
System.Index
type, 112
System.IndexOutOfRangeException
type, 247
System.InvalidCastException
type
description, 247
generics, 543
using, 472
System.InvalidOperationException
type. See InvalidOperationException
type
System.IO.DirectoryInfo
class
extension methods, 321
inner joins, 682
System.IO.FileAttributes
class, 443
System.IO.FileInfo
class
inner joins, 682
query expressions, 710
System.IO.FileStream
class, See FileStream
class
System.Linq.Async
NuGet package, 875
System.Linq
class, 199, 684–688
System.Linq.Enumerable
class, See Enumerable
class
System.Linq.Extensions.Enumerable
class, 677
System.Linq.ParallelEnumerable
class, 670, 906–907
System.Linq.Queryable
class
delegates, 620
queryable extensions, 694
System.MulticastDelegate
class
System
namespace, 199
System.Net
namespace, 483
System.NotImplementedException
type, 248
System.NullReferenceException
type. See NullReferenceException
type
System.Object
class
System.ObsoleteAttribute
, 797, 799–800
System.OutOfMemoryException
type, 514, 520
System.OverflowException
type, 73, 529
System.Range
type, 112
System.Reflection
class
delegates, 598
metadata, 772
System.Runtime.CompilerServices.CallSite<T>
type, 805–806
System.Runtime.CompilerServices.CompilerGeneratedAttribute
, 293
System.Runtime.ExceptionServices
class, 517
System.Runtime.InteropServices
class
unmanaged exceptions, 519
System.Runtime.Serialization
type, 526
System.Security.AccessControl.MutexSecurity
class, 932–933
System.StackOverflowException
type, 248, 514, 520
System.STAThreadAttribute
, 945
System.String
type, 59
System.Text
class
description, 199
type parameters, 557
System.Text.RegularExpressions
class, 199
System.Text.StringBuilder type
class, 69, 557
System.Threading
class, 199, 850–851
System.Threading.CancellationToken
class. See CancellationToken
class
System.Threading.Interlocked
class, 137, 926–928
System.Threading.ManualResetEvent
class, 934, 937
System.Threading.Monitor
class
locks, 432
thread synchronization, 918–920, 923–924
System.Threading.Mutex
class, 932–933
System.Threading.Tasks
class, 199, 823, 914
System.Threading.Tasks.TaskCanceledException
type, 846–847
System.Threading.Tasks.TaskScheduler
class, 887
System.Threading.Thread
class, 823
System.Threading.WaitHandle
class, 933–934
System.Timers
class, 944
System.Type
class
generic parameters, 780
type parameters, 779
System.ValueTuple
class, 96–98, 550–551
System.ValueType
class, 427, 771
System.Windows
class, 200
System.Windows.Forms
class, 944
System.Xml namespace, 200
escape sequence, 58
Tabs escape sequence, 58
Task-based Asynchronous Pattern (TAP), 823
async/await
syntax, 861–867, 890–891
asynchronous lambdas and local functions, 881–887
await using
statement, 874–875
description, 814
LINQ with IAsyncEnumerable
, 875–877
overview, 853
synchronization context, 887–889
synchronous issue example, 854–856
Task
class, 823
thread synchronization, 914
timers, 944
Task.Factory
class, 847–848, 914
Task Parallel Library (TPL)
asynchronous complexity, 859–861
cooperative cancellation, 843–847
description, 814
for
loop parallel iterations, 897
foreach
loop parallel iterations, 898–899
thread synchronization, 914
threads pools, 851
TaskCanceledException
type, 846–847
TaskCompletionSource<T>
class, 884–885
TaskContinuationOptions
enums, 831–834
Tasks
asynchronous. See Asynchronous tasks
description, 816
disposability of, 849
TaskScheduler
class, 887
TaskScheduler
property, 904
Temporary storage pools
reference types, 421
value types, 419
TemporaryFileStream
class, 495–497
Ternary operator, 154
Text
class
description, 199
type parameters, 557
ThenByDescending()
method, 678
this
keyword
extension methods, 322
nested classes, 328
static methods, 316
Thread pools
description, 816
multithreading, 823
Thread-safe code and operations
delegate invocation, 632
event notifications, 929
increment and decrement, 137
Thread synchronization
COM threading model, 945
concurrent collection classes, 938–939
need for, 931
volatile fields, 926
Threads
description, 816
multithreading. See Multithreading
synchronization. See Thread synchronization
ThreadStaticAttribute
, 941–942
throw
statements, 249–251, 512
ThrowIfCancellationRequested()
method, 847
Throwing exceptions, 512
in catch blocks, 521
error trapping, 241
Tildes (~)
complement operator, 167
finalizers, 494
list searches, 736
overriding, 468
Timers
class, 944
Timers for thread synchronization, 943–944
ToAsyncEnumerable()
method, 876–877
ToCharArray()
method, 116
ToDictionary()
method, 674–675
ToEnumerable()
method, 876
ToLower()
method, 64
Torn reads, 917
ToString()
method
conversions, 77
description, 364
Total ordering collections, 735–736
ToUpper()
method, 64
TPL. See Task Parallel Library (TPL)
Trace()
method, 799
TRACE
preprocessor identifier, 799
Trim()
method, 64
TrimEnd()
method, 64
TrimStart()
method, 64
TrimToSize()
method
queues, 748
True/false evaluations, 55
true
operator, overriding, 468–470
TryParse()
method
dynamic invocation, 777
enum, 442
Tuples
declaring and assigning, 92–96
GetHashCode()
and Equals()
overriding, 463–464
pattern matching, 368
projections, 669
return values, 207–208, 222–223
Two-dimensional arrays, 102, 104–105
Two's complement notation, 162–163
Type checking, 984
Type
class
type parameters, 779
Type parameters
cascading, 552
constraints. See Constraints
lists, 205
names, 544
type of, 779
Type safety, 537
CLI, 984
generics, 543
managed execution, 35
typeof()
method
attributes, 789
Types
anonymous. See Anonymous types
arrays. See Arrays
character, 56
CTS, 990
decimal, 49
declarations, access modifiers on, 479–480
definitions, 17
description, 23
dynamic, 803
generics, 540
hardcoding values, 50
implicitly typed local variables, 89–90
lambda expressions, 605
local variables, 23
nullable values, 86
overview, 45
strings. See Strings
Unicode standard, 56
unmanaged, 963
from unmanaged structs, 952–953
value. See Values and value types
well-formed. See Well-formed types
u
escape sequence, 58
uint
type, 46
ulong
type, 46
Unary expression trees, 618–619
Unary operators
UnauthorizedAccessException
type, 527, 901
Unboxing operation, 428–431, 434–436
Unchecked conversions, 73–75, 528–530
Uncompress()
method, 379
Underscores (_)
digit separators, 52
field names, 281
variable names, 24
VB line continuation character, 20
Undo operations
Unhandled exceptions
description, 241
reporting, 520
UnhandledException
type, 841
Unicode standard
character representation, 56–58
escape sequence, 58
localized applications, 56
Union()
operator, 693
Unity .NET frameworks, 39
Unmanaged code and types
buffer overflows, 109
description, 34
exceptions, 519
guidelines, 960
stack allocation, 967
UnobservedTaskException
type, 840
Unreachable end points in methods, 206–207
Unsafe code, 947
platform interoperability. See Platform interoperability
UserName
class, 933
ushort
type, 46
using
directive
deterministic finalization, 496–500
using static
directive
Validation, properties with, 283–285
value
keyword for properties, 278–279
Values and value types
CTS, 990
description, 418
enums. See enum values
generic instantiation, 582–583
hardcoding, 50
immutable, 424
inheritance and interfaces, 427
Values
property for sorted collections, 746
ValueTask<T>
class, 864, 867–869, 876–877
var
keyword
type declarations, 90
Variable parameters, defining index operators with, 752
Variables
for
loops, 170
foreach
loops, 174
immutable, 26
parameters, 197
query expressions, 707–708, 721
thread synchronization, 917–918
working with, 25
Variadic generic types, 552
Variance. See Contravariance; Covariance
Variants, 90
Verbatim strings
Versioning
encapsulation and polymorphism with protected interface members, 406–411
Vertical bars (|)
bitwise operators, 164
compound assignment, 167
Vertical tabs escape sequence, 58
Virtual abstract members, 357–360
Virtual Execution System (VES)
CLI, 982
description, 994
runtime, 35
Virtual functions in C++, 361
Virtual methods
virtual
modifier
base class overriding, 346–349
interface refactoring, 404
VirtualAllocEx()
method, 950
VirtualMemoryManager
class, 949
Visual Basic language vs. C#
global methods, 204
global variables and functions, 311
Imports
directive, 210
line-based statements, 20
Me
keyword, 268
named arguments, 238
redimensioning arrays, 114
variable declarations, 90
void type, 72
Visual Studio 2019
code building and executing, 13
debugging with, 9
preprocessor directives, 192–193
project and library references, 474–475
void
type
asynchronous method returns, 877–880
partial methods, 332
pointers, 969
return values, 207
Volatile fields, 926
volatile
modifier, 926
Wait()
method
asynchronous requests, 860
asynchronous tasks, 826
WaitAll()
method
asynchronous tasks, 826
thread synchronization, 933
WaitAny()
method
asynchronous tasks, 826
thread synchronization, 933
WaitForPendingFinalizers()
method, 496, 506
#warning
directive, 187, 189–190
Warnings
method overriding, 349
preprocessor directives, 186–191
Weak references in garbage collection, 491–493
Well-formed types
overriding object members, 451–464
overview, 451
resource cleanup. See Resource cleanup
Where()
operator, 666–667, 672–676
Whitespace
in strings, 60
trimming, 284
Win32Exception()
method, 953–955
Windows
class, 200
Windows Presentation Foundation (WPF)
description, 977
Windows UI applications, 889–891
WithCancellation()
method, 911
Work stealing, 899
WPF (Windows Presentation Foundation)
description, 977
Wrapped exceptions, 246, 527–530
Wrappers with API calls, 959
Write()
method
strings, 62
Write-only properties, 286–287
WriteLine()
method
strings, 62
x
escape sequence, 58
Xamarin .NET frameworks, 39
XAML (Extended Application Markup Language), 977
xcopy deployment, 989
XML (Extensible Markup Language)
delimited comments, 32
namespace, 200
overview, 33
reflection, 770
single-line comments, 32
XmlSerializer
class, 771
XOR (exclusive OR) operators
yield
statements, 15n
contextual keyword, 766
Zeros
division by, 131
floating-point types, 132
Zip()
method, 875
18.222.32.154