Index

Symbols

& (ampersands). See Ampersands (&)

<> (angle brackets)

generics, 540

XML, 33

* (asterisks). See Asterisks (*)

@ (at signs)

identifiers, 1617

verbatim strings, 60

(backslashes)

escape sequence, 5758

as literals, 60

^ (carets). See Carets (^)

: (colons). See Colons (:)

, (commas). See Commas (,)

{} (curly braces). See Curly braces ({})

$ (dollar signs) for string interpolation, 28, 6162

" (double quotes)

escape sequence, 57, 59

strings, 5960

= (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

overriding, 466, 468

precedence, 124

remainder operation, 123

. (periods)

fully qualified method names, 198

nested namespaces, 210, 483

null-conditional operator, 158

+ (plus signs). See Plus signs (+)

? (question marks)

command-line option, 783

conditional operators, 154155

null-coalescing operator, 157158

null-conditional operators, 158160

; (semicolons)

ending statements, 20

for loops, 171172

preprocessor directives, 189

' (single quotes)

characters, 57

escape sequence, 57

[] (square brackets)

arrays, 101103, 108

attributes, 783784

indexers, 750

null-conditional operators, 158160

~ (tildes)

complement operator, 167

finalizers, 494

list searches, 736

overriding, 468

_ (underscores). See Underscores (_)

| (vertical bars)

bitwise operators, 164

compound assignment, 167

logical operators, 151152

overriding, 466, 468

A

a escape sequence, 58

Abstract classes

defining, 357360

vs. interfaces, 413414

overview, 357

polymorphism, 361363

abstract modifier

interface refactoring, 405

limitations, 357, 386

Access modifiers

base class overriding, 353354

classes, 274276

derivation, 341344

finalizers, 495

getters and setters, 289291

type declarations, 479481

Accessing

arrays, 100, 106

base members, 354355

instance fields, 264265

properties, 425426

referent type members, 970

static fields, 312313

Accuracy of floating-point types, 128129

Acronyms as identifiers, 1516

Action delegate, 592594

Activation frames, 216

Add() method

collection initializers, 298, 654655

dictionaries, 739

interlocks, 927

lists, 733

Addition

binary operator, 123

compound assignment, 132

increment operator, 133

strings, 126127

unary operator, 122123

Address operator (&), 965

Addresses and pointers. See Pointers

AggregateException type, 247

asynchronous requests, 859860

parallel loops, 900901

PLINQ queries, 908, 911

publish-subscribe pattern, 640

tasks, 836840, 847

wrapped exceptions, 517

Aggregation for inheritance, 345

Ahead of time (AOT) compilation, 993

Alerts escape sequence, 58

Aliases

command-line option, 789793

namespaces, 213214

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

overriding, 466, 468

AND operations

bitwise operators, 164165

enums, 444445

logical operators, 152

Angle brackets (<>)

generics, 540

XML, 33

Anonymous functions, 600, 602

Anonymous methods, 600

internals, 610611

lambda expressions as replacement for, 587588

overview, 606607

parameterless, 607608

Anonymous types

collection initializers, 702703

generating, 702

local variables, 697701

overview, 91, 695696

selecting into, 698699

type safety and immutability, 700701

Antecedent tasks, 830831

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, 841843

Append() method, 69

AppendFormat() method, 69

Applicable calls, 238

ApplicationException type, 514

__arglist keyword, 17

args parameter for Main(), 1819

ArgumentException type, 523

description, 247

nameof operator, 514

properties, 285

throwing exceptions, 511512

ArgumentNullException type, 513514

description, 247

properties, 285

ArgumentOutOfRangeException type, 513514

Arguments

generics, 540

methods, 197198, 201

named, 237238

passed by value, 217

passing methods as, 590592, 596

Arithmetic operations, characters in, 127128

Arithmetic operators, 123124

ArithmeticException type, 248

Arity

generic methods, 569, 581582

tuples, 550552

type parameters, 550

Array accessors, 106

Arrays

anonymous types, 702703

assigning, 100

collection conversion to, 731

common errors, 117119

declaring, 9899, 101102, 108109

foreach loops, 657658

forward accessing, 100

instance members, 114115

instantiating and assigning, 102106

length, 109110

methods, 112114

null-conditional operators, 159

overview, 99

parameters, 226229, 552

ranges, 101, 111112

redimensioning, 114

reverse accessing, 100

strings as, 115117

unsafe covariance, 580

working with, 106109

ArrayTypeMismatchException type, 248

as operator, 373374

ASP.NET, 977

AsParallel() operator, 670, 906907, 911

AspNetSynchronizationContext type, 889

Assemblies

APIs, 40

attributes, 784785

boundaries, 479

building, 1011

CIL, 34

CLI, 35, 986989

constants, 324

extensions, 11

references, 472479

AssemblyCopyrightAttribute, 787

AssemblyFileVersionAttribute, 787

AssemblyVersionAttribute, 786787

Assert() method, 130

Assigning

arrays, 100, 102106

nulls to references, 71

nulls to strings, 70

pointers, 964965

tuples, 9296

variables, 2224

Assignment operators

associativity, 125

compound, 132, 167

delegates, 634, 641642

null-coalescing, 157158

overriding, 468

Associations

data with static members, 314

with instance fields, 263

Associativity of operators, 124125

Asterisks (*)

comments, 32

compound assignment, 132

indirection operators, 968

multiplication, 123

overriding, 466468

pointers, 963

precedence, 124

Async() method, 875

async operator, 861867, 890891

async return types, 869870, 877880

async void methods, 877880

AsyncEnumberable class, 875877

Asynchronous invocation, 818

Asynchronous lambdas, 881887

Asynchronous methods return types, 877881

Asynchronous pattern. See Task-based Asynchronous Pattern (TAP)

Asynchronous streams, 870874

Asynchronous tasks

complexities from, 822823

introduction, 824828

task continuation, 829836

task exceptions, 836840

thread exceptions, 840843

TPL, 823824

AsyncState property, 828

At signs (@)

identifiers, 1617

verbatim strings, 60

Atomic operations in multithreading, 819820

AttachedToParent task continuation option, 832

Attributes

custom, 787, 992

description, 769

enum, 443

FlagsAttribute, 795797

initializing, 789793

vs. interfaces, 415

named parameters, 794795

nullable, 306309

predefined, 797

properties, 783787

restricting, 793794

retrieving, 787789

System.ConditionalAttribute, 797799

System.ObsoleteAttribute, 799800

AttributeTargets flag, 794, 799

AttributeUsageAttribute class, 793795, 797

Automatically implemented properties

read-only, 287, 305306, 325326

reference type, 305306

structs, 423424, 426

working with, 279281

AutoResetEvent event, 937

Average() function, 693

Await() method, 876877

await operator

iterating, 892893

task-based asynchronous pattern, 861867, 890891

await using statement, 874875

AwaitAsync() method, 875, 877

AwaitWithCancellationAsync() method, 875876

B

 escape sequence, 58

Backslashes ()

escape sequence, 5758

as literals, 60

Backspace escape sequence, 58

Base Class Library (BCL)

description, 977, 993

purpose, 35, 979

type names, 4649, 56, 59

Base class overriding

constructor invocation, 355356

members, 353355

new modifier, 349353

overview, 346

sealed modifier, 353354

virtual modifier, 346349

Base classes

derived object conversion to, 339

inheritance, 257258

protected member access in, 344

Base types

casting between derived types, 339340

classes, 258259

description, 336

BCL (Base Class Library)

description, 977, 993

purpose, 35, 979

type names, 4649, 56, 59

Binary digits (bits), 162163

Binary expression trees, 618619

Binary operators

associativity, 125

compound assignment, 132, 468

non-numeric types, 126127

null-coalescing, 157

overriding, 466467

overview, 123124

relational and equality, 150151

Binary values

conversions to, 165167

floating-point, 47

literals, 53

shift operators, 163

BinaryExpression expression trees, 623

BinarySearch() method

arrays, 112114

list searches, 736

BinaryTree<T> class

constraints, 553557

index operators, 152

iterators, 755756, 759762

parameters, 572

Binding

dynamic, 801, 806807

extension methods, 412

late, 518, 985, 992

metadata, 992

Bits (binary digits), 162163

Bitwise operators

bits and bytes, 162163

complement, 167, 736737

compound assignment, 167

enums, 444445

for positions, 181182

shift, 163164

working with, 164167

Block statements. See Code blocks

BlockingCollection<T> class, 938939

Boolean (bool) type

array initial values, 104

conversions, 75

flow control, 149

lambdas, 593

logical operators, 151153

overview, 5556

relational and equality operators, 150151

Boolean expressions for if statements, 142

Boolean operators

logical, 151155

overriding, 468470

Bounds

arrays, 109110

floating-point types, 131

Boxing

avoiding, 435436

generics for, 543

idiosyncrasies, 432434

in loops, 448

overview, 428432

Brand casing for namespaces, 482

Break() method, 905

break statements

lambda expressions, 606

overview, 141

switch statements, 177178

working with, 180181

yield break, 764

Breaking parallel loops, 904905

Brittle base class problem, 349351

Bubble sorts, 588602

Buffer overflows

C# vs. C++, 109110

managed execution, 986

type safety, 35, 984

unsafe code, 962

byte type, 46

Bytes, 162163

C

C language and C# syntax similarities, 23

C++ language vs. C#

arrays, 101102

Boolean conversions, 75

buffer overflows, 109110

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, 348349

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

syntax similarities, 23

Variant and var, 90

void type, 71, 90

Calculated properties, 287289

Call sites, 217

Call stacks for methods, 216217

Callback functions, 587

CallerMemberName parameter attribute, 782

Calling

collection initializers, 297298

constructors, 294295

external functions, 956958

object initializers, 296297

CallSite<T> type, 805806

camelCase

description, 16

parameter names, 205, 268, 300

property names, 282

tuples, 95

variable names, 24, 92

"can do" relationships, 377378

Cancel() method

parallel iterations, 903

PLINQ queries, 911

tasks, 845846

Canceling

iterations, 763764

parallel loops, 901903

PLINQ queries, 908911

tasks, 843849

CancellationToken class

asynchronous methods, 885

asynchronous streams, 872873

overview, 843847

PLINQ queries, 911

CancellationToken property, 904

CancellationTokenSource class, 845846, 903, 911

Capacity of lists, 731733

Capture() method, 517

Captured outer variables, 611612

Carets (^)

arrays, 107108

bitwise operators, 164

compound assignment, 167

index from end operator, 99, 107, 108, 110, 112, 118

logical operators, 152

overriding, 466, 468

Carriage returns

escape sequence, 58

newlines, 66

Cartesian products

inner joins, 684

query expressions, 723

Case labels

goto statements, 185

switch statements, 177, 179

Case sensitivity

C++ similarity, 3

importance, 2

literal suffixes, 52

suffixes, 5152

Casing

identifier formats, 1516

local variables, 24

cast operator and casting

base and derived types, 339340

defining, 341

enums, 440441

generic methods, 572573

implicit conversions, 76

in inheritance chains, 340

overriding, 470471

overview, 7277

Catch blocks

exceptions, 514516, 518520

general, 248249

rethrowing exceptions, 251

working with, 242245

Catching exceptions, 241242, 514516, 518519

cells member in arrays, 115

Central processing units (CPUs)

description, 815

multithreading, 814, 818

PLINQ queries, 670

Centralizing constructor initializers, 301302

Chains

circular, 930

constructors, 300301

delegates, 633634, 637638, 640

expressions, 158160

inheritance, 338340

iterators, 762

null-coalescing operator, 158

queries, 722

tasks, 830831, 853

Characters (char) types

arithmetic operations, 127128

array initial values, 104

description, 23, 56

Checked conversions, 7375, 528530

checked keyword, 7375, 529530

CheckForOverflowUnderflow property, 529

Child types, 258, 336

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

abstract, 357363

access modifiers, 274276

associated data, 314

concrete, 357

constraints, 560561

constructors. See Constructors

declaring, 259260

deconstructors, 309311

defined, 260

delegates, 597600

encapsulation, 261262, 323326

extension methods, 321322

files for storing and loading, 270273

generics, 540544, 779780

hierarchy, 257258

inextensible, 320

inheritance. See Inheritance

instance fields, 262265

instance methods, 265266

instantiating, 260261

interfaces. See Interfaces

libraries, 472475

members, 262

methods, 197198

multiple interfaces, 545546

multiple iterators in, 766767

nested, 326328

nullable attributes, 306309

object-oriented programming, 256259

overview, 255256

partial, 329332

properties. See Properties

refactoring, 336337

sealed, 345

static, 319321

static members. See Static members

vs. structs, 763

this keyword, 266270

Clear() method, 112, 114

CLI. See Common Language Infrastructure (CLI)

Clock speeds, 813

Clone() method, 114115

Close() method, 497

Closed over outer variables, 611612

Closures, 614

CLR (Common Language Runtime)

description, 982, 994

enums, 440441

namespaces, 481483

CLS (Common Language Specification)

description, 994

libraries, 35

metadata, 991

CLSCompliant attribute, 991

CLU language, 754

Clusters, 754

Code access security, 35

Code blocks

error trapping, 242244

if statements, 144147

loops, 169170

scope, 147149

Code editors for preprocessor directives, 191193

Code readability. See Readability

CodeAnalysis class, 306309

Cold tasks, 825

Collect() method, 490, 506

Collections

anonymous types, 702703

class categories, 731733

dictionaries, 738744

foreach loops, 174175, 661662

IEnumerable<T>, 657663

indexers, 750752

initializers, 297298, 654657, 702703

interfaces, 653654, 728731

iterators. See Iterators

join operations. See Join operations

linked lists, 749

null values, 753

overview, 727728

queues, 748

searching, 736738

shared states, 660

sorted, 745747

sorting, 734735

stacks, 747

standard query operators. See Standard query operators

thread synchronization, 938939

total ordering, 735736

Collisions, name, 198

Colons (:)

conditional operators, 154155

constraints, 561

constructors, 301

derived classes, 336

hexadecimal format, 54

labels, 185

COM threading model, 945

Combine() method

delegates, 558559, 634, 650651

hash codes, 455

parameters, 217218, 220, 226229

COMException type, 514

Command-line arguments, 19, 214216

CommandLineInfo class, 773779

CommandLineRequiredAttribute, 797

CommandLineSwitchAliasAttribute, 797

CommandLineUtils package, 773n

Commas (,)

arrays, 99, 102, 104, 106

attributes, 787

constraints, 561

enums, 447

for loops, 173

interfaces, 384

methods, 201

parameters, 205

variable declarations, 23, 499

Comments

guidelines, 33

overview, 3033

XML, 485489

Common Intermediate Language (CIL)

anonymous types, 697698

assemblies, 34

boxing code, 428432

compilation to, 974975

description, 994

events, 649650

general catch blocks, 519

generics representation, 581582

ILDASM, 36

indexers, 751

metadata, 770, 991992

outer variable implementation, 613614

output, 3739

properties, 291293

purpose, 989990

Common Language Infrastructure (CLI)

assemblies, 986989

Base Class Library, 979

CIL, 989990

CLS, 991

compilation to, 979981

CTS, 990

description, 974975, 994

encapsulation, 985

garbage collection, 982984

implementations, 975976

manifests, 986989

metadata, 991992

Microsoft .NET Framework, 975977

modules, 986989

multicast delegates, 636637

namespaces, 482

.NET Core, 977978

.NET Native feature, 993

.NET Standard version, 978979

overview, 3435, 973

P/Invoke, 948960

performance, 985986

platform portability, 985

runtime, 982984

type safety, 984

Xamarin compiler, 978

Common Language Runtime (CLR)

description, 982, 994

enums, 440441

namespaces, 481483

Common Language Specification (CLS)

description, 994

libraries, 35

metadata, 991

Common Type System (CTS), 34, 990, 994

Compacting objects in garbage collection, 490

Compare() method, 56, 63

CompareExchange() method, 926927

CompareTo() method

collection sorts, 734735

interfaces, 556557

tree sorts, 553554

Comparing

binary tree nodes, 556557

collections items, 734735

compare/exchange pattern, 926927

floating-point types, 129130

strings, 56, 63

Comparison operators

overriding, 464465

pointers, 969

Compatibility between enum types, 440441

Compilation

ahead of time, 993

assemblies, 1011

disassembling, 36

to machine code, 979981

sample output, 3739

source code, 38, 3435

static vs. dynamic, 807808

CompilerGeneratedAttribute, 293

Complement operator (~), 167

Complexity of asynchronous requests, 859861

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, 6263

Concat() operator for queries, 693

Concatenating strings, 6163, 126127

Concrete classes, 357

Concurrent collection classes, 938939

Concurrent operations, 817818

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

working with, 154155

Conditional types, 5556

ConditionalAttribute, 797799

ConditionalExpression expression trees, 623

Conditions

for loops, 172

if statements, 142

Consequence statements in if statements, 142

Console

comments, 3033

input, 2627, 197

newlines, 59, 66

output, 19, 2833, 197

round-trip formatting, 5455

string methods, 62

const keyword

constants, 137138

encapsulation, 323324

ConstantExpression expression trees, 623

Constants

expressions and locals, 137138

pattern matching, 366368

switch statements, 177

Constraints

classes, 560561

constructor, 562565

delegates, 558559

generic methods, 571572

inheritance, 565567

interfaces, 554557

limitations, 567568

multiple, 561562

notnull, 560

operators, 567568

overview, 553555

structs, 560561

type parameters, 557558

unmanaged, 559560

Constructed struct types, 560

Constructors

attributes, 789793

base classes, 355356

chaining, 300301

collection initializers, 297298

constraints, 562565

declaring, 293295

default, 295296

finalizers, 298

generics, 547

initializers, 300302

methods called during, 348349

new operator, 294295

non-nullable reference type properties, 303306

object initializers, 296297

overloading, 298300

overview, 293

propagating exceptions from, 507

static, 316318

structs, 424

Contains() method

list searches, 736

stack searches, 747

ContainsGenericParameters property, 779780

ContainsKey() method, 741

ContainsValue() method, 741

Context switches, 137, 817820, 850

Contextual keywords, 15, 766

Continuation of tasks, 829836

continue statements

lambda expressions, 606

overview, 140

switch statements, 177

working with, 182184

ContinueWith() method

asynchronous requests, 859

synchronization context, 888889

tasks, 829831, 834835, 839840

Contravariance

delegates, 609

generics, 573580

type parameters, 577579

Control flow. See Flow control

Conversions

as operator, 373374

to binary representation, 165167

Boolean type, 75

boxing, 428432

casts. See cast operator and casting

checked and unchecked, 7375, 528530

collections to arrays, 731

covariant, 574

dynamic objects, 803

enums, 439443

explicit, 7273

false return values, 7779

implementing classes and interfaces, 390

implicit, 7576

overriding operators, 470472

overview, 72

type safety, 35

without casts, 7677

Cooperative cancellation, 843847

Copying

arrays, 115

directories, 316, 321322

null values, 85

reference types, 8384, 421

variables, 418419

CopyTo() method

collections, 730731

directories, 316, 321322

Core .NET frameworks, 39

CoreCLR compiler, 975, 977

Cores, 670, 815, 817

Count() method

description, 693

elements, 671674

index-based collection, 412

Count property for collections, 730731

CountdownEvent event, 937938

CountOccurrencesAsync() method, 860861, 864866

Covariance

in arrays, 580

delegates, 609

generics, 573580

out modifier, 575577

CPUs (central processing units)

description, 815

multithreading, 814, 818

PLINQ queries, 670

Create() method, 551

Cryptographer class, 874

.cs file extension, 9

CTS (Common Type System), 34, 990, 994

Curly braces ({})

arrays, 102103

classes, 259

code blocks, 144147

code formatting, 22

collection initializers, 297, 655656

lambda expressions, 603

methods, 18

namespaces, 482

object initializers, 296

pattern matching, 370

properties, 278

string interpolation, 29, 6162, 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

Custom attributes, 787, 992

Custom conversions, 340341

Custom exceptions, 523526

Custom objects in dynamic programming, 808811

Custom value types for structs, 422427

D

Data namespace, 199

Data persistence, files for, 270273

Data types. See Types

DataBinder class, 771

Deadlocks

avoiding, 929930

causes, 821823

Debug() method, 799

DEBUG preprocessor identifier, 799

Debugging

preprocessor directives for, 188

source code, 89

Decimal type, 49

Declaration spaces in code blocks, 147149

Declaring

arrays, 9899, 101102, 108109

await using statement, 874875

BinaryTree<T> class, 553554

class type constraints, 557558

classes, 259260

constants, 323

constructors, 293295

deconstructors, 311

delegate types, 592595

enums, 437438

events, 643644, 648649

external methods, 948949

generic interfaces, 544545

generic methods, 568569

instance fields, 263264

interface constraints, 556557

local variables, 2223

Main() method, 1819

methods, 203204

namespaces, 482484

out variables, 222

parameters, 205

pointers, 963964

properties, 277279

read-only automatically implemented properties, 325326

read-only fields, 324325

return types, 206208

static constructors, 316318

static fields, 312

structs, 422423

tuples, 9296

types from unmanaged structs, 952953

variables, 2324

Deconstructors, 309311

Decrement() method, 137, 927928

Decrement operators

description, 133

loop example, 133136

thread-safe, 137

Default constructors, 295296

Default interface members

vs. extension methods, 411413

versioning, 398400

default operator for generics, 547549

default sections in switch statements, 179, 184

Default types, 5052

Default values

generics, 547549

structs, 424

DefaultIfEmpty() method, 688689

Deferred execution

LINQ, 672676

query expressions, 711715

#define directive, 187, 189

Defining

abstract classes, 357360

attributes, 786

calculated properties, 288289

cast operators, 341, 470471

custom conversions, 340341

custom exceptions, 523526

enums, 438439, 445

finalizers, 494495

generic classes, 542

generic constructors, 547

generic methods, 568570

indexers, 750752

iterators, 754

namespaces, 481484

nested classes, 326328

partial classes, 329332

preprocessor symbols, 189

publishers, 627628

stacks, 537

static methods, 315316

subscriber methods, 626627

Delay() method, 944

Delegate class, 597598

delegate keyword, 592

Delegate type, 558559

Delegates

constraints, 558559

deferred execution, 715

event notifications, 928929

events, 647648

vs. expression trees, 620621

function pointers to, 960

instantiating, 595597

internals, 597600, 636637

introduction, 588590

invoking, 629632, 634636

method returns and pass-by-reference, 640

nesting, 594595

null-conditional operators, 161

overview, 587588

predicates, 666667

process exits, 506

publish-subscribe pattern operators, 633634

statement lambdas for, 601604

structural equality, 608609

tasks, 824

types, 590594

unsafe code, 971972

delete operator, 262

Deleting files, 496

Delimited comments, 32

Delimiters, 1920

DenyChildAttach task continuation option, 832

Dependencies in libraries, 10

Dequeue() method, 748

Dereferencing

description, 83

null-conditional operator for, 513

null references, 8586

null values, 87

pointers, 968970

Derivation

casting between base and derived types, 339340

custom conversions, 340341

extension methods, 344

interfaces, 397398

overview, 336338

private access modifier, 341342

protected access modifier, 342344

sealed classes, 345

single inheritance, 345

from System.Object, 363365

Derived members, 335

Derived objects converted to base class, 339

Derived types

casting between base types, 339340

classes, 258259

description, 336

DescriptionAttribute, 786

Deserialize() method, 572573

Deterministic destruction, 502, 983

Deterministic finalization, 496500

Deterministic resource cleanup, 262

Diagnostics class

debugging with, 799

notifications, 885

nullable attributes, 306309

processes, 815

Diagramming interfaces, 395396

Dictionaries

collection initializers, 656

interfaces, 728730

key equality, 743744

sorted, 745747

thread synchronization, 939

working with, 738743

Dictionary<TKey, TValue> class

collections, 658

working with, 738743

Digit separators, 5253

Dimensions for arrays, 102106, 114

Directives

dynamic, 803

preprocessor. See Preprocessor directives

strings, 6465

Directories, copying, 316, 321322

DirectoryInfo class

extension methods, 321

inner joins, 682

DirectoryInfoExtension class, 315316, 321322

DisallowNull attribute, 307

Disambiguating multiple Main() methods, 214216

Disassembling programs, 36

Discards

out parameters, 222

tuples, 96

DispatcherTimer class, 944

Disposability of tasks, 849

Dispose() method

collections, 661

finalization, 500502

resource cleanup, 495, 497499

DisposeAsync() method, 874875

Distinct members in query expressions, 723724

Distinct() operator

description, 693

query expressions, 723724

Division

binary operator, 123

compound assignment, 132

shift operators, 164

by zeros, 131

DllImport attribute, 949, 953

DLLs (dynamic link libraries), 1011

do/while loops

overview, 140

working with, 168170

Documentation

reflection, 770

XML files, 487489

Dollar signs ($) for string interpolation, 28, 6162

DotGNU Portable.NET compiler, 976

Dotnet CLI

code building and executing, 12

NuGet references, 475476

project and library references, 474

working with, 46

Double quotes (")

escape sequence, 57, 59

strings, 5960

double type

overview, 4749

special characteristics, 128129

DownloadData() method, 856

DownloadDataTaskAsync() method, 858860, 865

DownloadString() method, 856

Drawing class, 199

Duck typing, 662

Duplicating interfaces, 545546

dynamic data type principles and behaviors, 803805

Dynamic invocation

delegates, 558559

members, 773779

nameof operator, 781782

Dynamic link libraries (DLLs), 1011

Dynamic programming

binding, 806807

custom objects, 808809

description, 769

overview, 800801

principles and behaviors, 803805

reflection, 801802

vs. static compilation, 807808

DynamicInvoke() method, 558559

DynamicObject class, 808811

E

Editors

dotnet CLI, 46

preprocessor directives, 191193

source code, 34

Visual Studio 2019. See Visual Studio 2019

Elements, counting, 671672

#elif directive, 186, 188

else clauses, 142

#else directive, 186, 188

Empty collections, 753

Empty property for events, 645

Empty strings, 70

Encapsulation

classes, 261262

CLI, 985

const modifier, 323324

information hiding, 274276

object-oriented programming, 257

with protected interface members, 406411

publications, 642643

readonly modifier, 324326

subscriptions, 641642

well-formed types, 479481

EncryptAsync() method, 874

#endif directive, 188

#endregion directive, 191193

EndsWith() method, 63

Enqueue() method, 748

Enter() method with monitors, 432, 918920, 922924

Enum class, 439, 442

enum values

conversions, 441443

flags, 443447

FlagsAttribute, 795797

metadata, 772773

overview, 437440

parsing, 78

type compatibility, 440441

Enumerable class

delegates, 621

element counting, 671672

filters, 667

inner joins, 682, 684688

methods, 691693

parallel queries, 907

query expressions, 714

sorts, 676678

standard query operators, 663

Enumerator patterns for iterators, 754755

Environment class

command-line arguments, 19, 216

newlines, 66

thread synchronization, 933

Equality

C# vs. C++, 150

collections, 744745

delegates, 608609

dictionary keys, 743744

floating-point types, 129132

with null, 156157

objects, 456459

operators, 150151

EqualityComparer<T> class, 463, 743

Equals() method

collections, 744745

description, 364

with GetHashCode(), 453454, 744

implementing, 460462

null values, 87

overriding, 455464

reflection, 427

Equals signs (=)

compound assignment, 132, 167, 468

delegates, 632634, 641642, 650

equality operator, 55

null checks, 86

null-coalescing operator, 157158

overriding, 464465

pointers, 969

precedence, 124

properties, 278

relational and equality operators, 150151

shift operators, 163164

variable assignment, 2425

Equi-joins, 688

#error directive, 187, 189190

Error handling. See also Exceptions

catch blocks, 248249

exception class inheritance, 246248

with exceptions, 239240

P/Invoke, 953955

publish-subscribe pattern, 637640

throw statements, 249251

trapping, 241246

Errors

array coding, 117119

preprocessor directives for, 186191

Escape sequences, 5758

Essential source code, 1213

EssentialCSharp.sln file, 12

Etch A Sketch game, 534537

Evaluation of operators, 125

event keyword, 643644

EventArgs class, 645647

EventHandler<T> class, 644, 647648, 650651, 887

Events

coding conventions, 644647

declaring, 643644, 648649

generics and delegates, 647648

implementation, 650651

internals, 648650

listeners, 835836

overview, 625

publication encapsulation, 642643

publish-subscribe pattern. See Publish-subscribe pattern

purpose, 641

subscription encapsulation, 641642

thread synchronization, 928929

Exception conditions, 516

Exceptional continuation, 829

ExceptionDispatchInfo class

asynchronous requests, 860

purpose, 517518

Exceptions

catch blocks, 248249, 514516, 518519

class inheritance, 246248

custom, 523526

error trapping, 241246

expected situations, 252253

guidelines, 514, 519523

overview, 239240, 511

parallel loops, 900901

PLINQ queries, 908, 911

propagating from constructors, 507

publish-subscribe pattern, 637640

rethrowing, 517518, 522523, 527530

serializable, 526

tasks, 836840

threads, 840843

throw statements, 249251

types, 511514

ExceptionServices class, 517

Exchange() method, 927

Exclamation points (!)

equality operators, 55

generics, 582

inequality operators, 150151

logical operators, 153

null-forgiving operators, 160161

overriding, 464465, 468

pointers, 969

Excluding code, preprocessor directives for, 188

Exclusive OR (XOR) operators

bitwise, 164165

logical, 152153

Executables, stand-alone, 1112

ExecuteSynchronously task continuation option, 833

Execution time, 35

ExecutionEngineException type, 514

Exit() method with monitors, 432, 918920, 923924

Expanded form for parameters, 227

Explicit casts

base and derived types, 339

enums, 440441

guidelines, 471472

overview, 7273

Explicit deterministic resource cleanup, 262

Explicit member implementation, 386390

Exponential notation, 52

Expression bodied members

declaring, 208

properties, 279

Expression trees

deferred execution, 715

vs. delegates, 620621

description, 616

examining, 621623

object graphs, 618619

SQL queries, 617618

Expressions

constant, 137138

lambda. See Lambda expressions

query. See Query expressions

Extended Application Markup Language (XAML), 977

Extensible Markup Language. See XML (Extensible Markup Language)

Extension methods

classes, 321322

vs. default interface members, 411413

derivation, 344

interfaces, 394395

Extensions, file, 9

External methods and functions

calling, 956958

declaring, 948949

F

f escape sequence, 58

f-reachable (finalization) queues, 298, 500501

Factory interfaces for constructor constraints, 564

FailFast() method, 514

Failure type, 514

false operator, overriding, 468470

Fat arrow notation (=>) for lambda expressions, 608

FCL (Framework Class Library), 979, 993994

Fibonacci numbers, 168169

Fields

guidelines, 281283

instance. See Instance fields

static members, 311314

strings, 66

thread synchronization, 926

FIFO (first in, first out) collections, 748

FileAttributes class, 443

FileInfo class

inner joins, 682

projections, 668669, 717718

query expressions, 710

Files

deleting, 496

extensions, 9

Java language vs. C#, 10

project, 10

storing and loading with, 270273

FileStream class

finalizers, 495

IAsyncDisposable, 874

storing and loading files, 270273

ToString(), 452

Filters

Browse, 477

collections, 593594, 666667, 672676

exceptions, 521523

query expressions, 706, 715716

Finalization, deterministic, 496500

finalization (f-reachable) queues, 298, 500501

finalize() method, 364

Finalizers

constructors, 298

generics, 547

resource cleanup, 493496, 500501

structs, 426427

finally blocks in error trapping, 244246

FindAll() method, 737738

First in, first out (FIFO) collections, 748

fixed statement for pointers, 966967

Flags, enums as, 443447

FlagsAttribute

enums, 446447

overview, 795797

Flatten() method, 860

Flattening sequences in query expressions, 722723

float type

overview, 4748

special characteristics, 128129

Floating-point types

equality issues, 129132

overview, 4749

special characteristics, 128129

Flow control

Boolean expressions, 149155

code blocks, 144147

description, 121

for loops, 170174

foreach loops, 174175

if statements, 142144

introduction, 138141

jump statements, 180185

preprocessor directives, 186193

scope, 147149

switch statements, 176179

task continuation, 829

threads, 816

while and do/while loops, 168170

for loops

overview, 140, 170174

parallel iterations, 895898

For() method, 897898

Forcing resource cleanup, 503507

foreach loops

arrays, 657658

async streams, 873874

collections, 661662

enumerator patterns, 754

IEnumerable<T>, 658659, 662663

overview, 140, 174175

parallel iterations, 898899

Form feeds escape sequence, 58

Formal parameter lists, 205

Format items, 29

Format() method, 6263, 65

Format strings, 2930

FormatException type, 244, 247

FormatMessage() method, 953

Formatting

hexadecimal format, 54

round-trip, 5455

with string interpolation, 28

strings, 6566

Forward accessing arrays, 100

Forward slashes (/)

command-line option, 783

compound assignment, 132

overriding, 466, 468

precedence, 124

XML comments, 32, 486487

XML elements, 33

Fragile base class problem, 349351

Framework Class Library (FCL), 979, 993994

Framework Design Guidelines, 15

Frameworks

APIs, 40

.NET. See .NET frameworks

from keyword in query expressions, 707709, 714, 722723

FromCurrentSynchronizationContext() method, 887

Full outer joins, 679

Fully qualified method names, 198

Func delegate, 592594

Functions

external, 956958

pointers to delegates, 960

G

Garbage collection

CLI, 982984

managed execution, 35

Microsoft .NET framework, 489491

objects, 261

overview, 489

resource cleanup. See Resource cleanup

weak references, 491493

GC class

finalization, 500

finalizers, 496

garbage collection timing, 490

resource cleanup, 506508

General catch blocks, 248249, 518520

Generics

benefits, 543544

CIL representation, 581582

classes, 540544

constraints. See Constraints

constructors, 547

covariance and contravariance, 573580

default values, 547549

defining, 542

delegates, 609

events, 647648

examples without, 534539

finalizers, 547

instantiating, 582584

interfaces and structs, 544546

internals, 580584

introduction, 539540

Java, 584585

lazy loading, 509510

linked lists, 749

methods, 568573

nested, 552553

overview, 533

reflection, 779781

tuples, 550552

type parameters, 308309, 542545, 549552, 780781

working with, 540542

get keyword for properties, 278279

GetAsyncEnumerator() method, 872873

GetAwaiter() method, 870, 881

GetCommandLineArgs() method, 216

GetCustomAttributes() method, 788790

GetEnumerator() method

duck typing, 662

iterators, 755, 757761

purpose, 660

queryable extensions, 694695

standard query operators, 663

GetFiles() method

directories, 321

inner joins, 682

GetGenericArguments() method, 780

GetHashCode() method

collections, 744745

description, 364

overriding, 453455, 463464

value types, 427

GetLastError() method, 953

GetLength() method, 114

GetMethods() method, 771

GetProperties() method, 771772

GetResult() method, 881

getters

access modifiers, 289291

properties, 67, 278279

GetType() method

description, 364

null values, 87

objects, 462

reflection, 771773

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

switch statements, 184185

Graphs for expression trees, 618619

Greater than signs (>)

generics, 540

overriding, 464, 466

pointers, 969

referent member access, 970

relational operators, 150

shift operators, 163164

XML, 33

group clauses in query expressions, 707, 720722

group by clause, 719

GroupBy() method, 685686

Grouping query expressions, 718721

GroupJoin() method

inner joins, 686688

outer joins, 688691

H

Handle() method

asynchronous requests, 860

task exceptions, 839

Handlers for process exits, 506

Hardcoding values, 50

HasFlags() method, 444

Hash codes and tables

collection equality, 744745

dictionaries, 741

GetHashCode(), 453455

Hash symbols (#) for preprocessor directives, 186

Hat operator (^) for arrays, 107108

Header files, 208

Heap

boxing, 428

new operator, 262

reference types, 83, 420421

HelloWorld.dll file, 10

HelloWorld program

assemblies, 1011

CIL output, 3739

compiling, 1011

debugging, 89

description, 23

dotnet CLI for, 46

preparing, 34

project files, 910

stand-alone, 1112

Visual Studio 2019 for, 68

Hexadecimal numbers

formatting numbers as, 54

notation, 5253

Unicode characters, 58

HideScheduler task continuation option, 833

Hierarchy of classes, 257258

High-latency operations

async/await syntax, 862867

asynchronous example, 856858

synchronous example, 854856

WPF example, 889891

Hill climbing, 899

Hold and wait conditions in deadlocks, 930

Hooking up publishers and subscribers, 628629

Horizontal tabs escape sequence, 58

Hot tasks, 825

Hungarian notation, 16

Hyper-Threading, 815

Hyphens (-). See Minus signs (-)

I

I/O-bound operations

latency, 814

performance considerations, 818820

IAsyncDisposable interface, 874875

IAsyncEnumerable<T> interface

async returns, 880881

asynchronous streams, 872874

LINQ with, 875877

IAsyncEnumerator<string> interface, 877, 881

ICollection<T> interface

collection initializers, 654655

element counting, 671672

members, 730731

IComparable<string> interface, 734

IComparable<T> interface, 554557, 572

IComparer<T> interface, 734735

Id property for asynchronous tasks, 828

IDE (integrated development environment)

debugging support, 8

Visual Studio 2019, 6

Identifiers

guidelines, 16

keywords as, 17

overview, 1516

Identity of objects, 456459

IDictionary<TKey, TValue> interface, 728730

IDisposable interface

resource cleanup, 497501, 661662

tasks, 849

IDynamicMetaObjectProvider interface, 808

IEnumerable<T> interface

collections, 657663, 730731

delegates, 620621

element counting, 671672

filters, 667

foreach loops, 658663, 754

iterators, 755, 760

PLINQ queries, 911

projections, 669

query expressions, 708709, 714

standard query operators, 663

task-based asynchronous pattern, 877

yield statement, 767

IEnumerator<T> interface

foreach loops, 658662

iterators, 755756, 764

yield statement, 767

IEqualityComparer<T> interface, 743744

IEquatable<T> interface, 463

#if directive, 186, 188

if statements

Boolean expressions, 149

code blocks, 144147

continue statement replacement, 183184

nested, 142144

overview, 139

switch statements for, 178

working with, 142

IFileCompression interface, 379

IGrouping type, 719, 721

ILDASM (IL Disassembler), 3637

IList<T> interface, 728730

IList<TKey> interface, 746

IList<TValue> interface, 746

Immutability

anonymous types, 700701

delegates, 598

strings, 26, 6769, 968970

value types, 424

Immutable library, 939

Implementing class conversions with interfaces, 390

Implicit conversions

base and derived types, 339

guidelines, 471472

types, 72, 7576

Implicit deterministic resource cleanup, 262

Implicit member implementation, 386390

implicit operator for types, 7576

Implicitly typed local variables, 8990

import directive, 210

in parameters, 223

Including code, preprocessor directives for, 188

Increment() method, 137, 927928

Increment operators

description, 133

prefix and postfix, 134136

thread-safe, 137

Indenting code

if statements, 144, 146

readability, 2122

Index operator

lists, 731733

variable parameters, 752

Index from end operator, 99, 107, 108, 110, 112, 118

Index type, 112

IndexerNameAttribute, 751

Indexers, 750752

Indexes

arrays, 99, 107108

dictionaries, 740741

list searches, 736

sorted collections, 746

IndexOf() method, 736

IndexOutOfRangeException type, 247

Indirection operators for pointers, 968969

Inequality

floating-point types, 129132

with null, 156157

operators, 150151

Inextensible classes, 320

Inferences for generic methods, 569571

Infinite recursion errors, 231

Infinity value, 131

Infix notation for binary operators, 123

Information hiding in encapsulation, 274276

Inheritance

abstract classes, 357363

base class overriding. See Base class overriding

casting in, 340

constraints, 565567

definitions, 335336

derivation. See Derivation

exception classes, 246248

interfaces, 390393

is operator, 365371

overview, 257259, 335

System.Object class in, 363365

value types, 427

Initial section in for loops, 172173

Initialization, lazy, 508510

Initializers

collections, 297298, 654657

constructors, 300302

object, 296297

Initializing

anonymous type arrays, 702703

arrays, 104106, 108

attributes, 789793

dictionaries, 656

fields, 548

loop counters values, 170

static members, 312313, 317318

structs, 424426

Inner classes, 328

Inner joins

description, 679

one-to-many relationships, 686688

performing, 682686

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

Input, console, 2627

Insert() method, 69

Inserting dictionary items, 740741

Instance fields

accessing, 264265

declaring, 263264

description, 262263

initializing, 312313

Instance members

arrays, 114115

strings, 62

working with, 265266

Instantiation

arrays, 102106

classes, 260261

defined, 19

delegates, 595597

generics, 582584

Integers and int type

characteristics, 4647

characters, 127

conversions, 72

default, 50

description, 23

enums, 439

overflow, 528530

vs. strings, 240241

Integrated development environment (IDE)

debugging support, 8

Visual Studio 2019, 6

IntelliSense feature, 708

Interfaces

vs. abstract classes, 413414

vs. attributes, 415

collections, 728731

constraints, 554557

converting between implementing classes, 390

default members, 411413

deriving, 397398

diagramming, 395396

duplicating, 545546

extension methods, 394395, 411413

generics, 544546

implementation, 377378, 384390

inheritance, 390393

overview, 377

polymorphism, 380384

purpose, 378380

refactoring features, 401405

value types, 427

versioning. See Versioning

Interlocked class

increment and decrement operators, 137

working with, 926928

internal access modifier

description, 481

interface refactoring, 402

on type declarations, 479480

Interoperability. See Platform interoperability

InteropServices class

SafeHandle, 955956

unmanaged exceptions, 519

Interpolation of strings, 2830, 6162

Intersect() operator, 693

into clause in query expressions, 721722

IntPtr class, 951, 963

InvalidAddressException type, 523

InvalidCastException type

description, 247

generics, 543

using, 472

InvalidOperationException type

catch blocks, 516517

collections, 663

description, 247

null values, 87

tasks, 838

wrapped exceptions, 527

Invocation

base class constructors, 355356

delegates, 629632, 634636

dynamic, 773779

referenced packages and projects, 477479

using statement, 499

Invoke() method

delegates, 630

dynamic invocation, 777

events, 161

IOException type, 520, 527

IOrderedEnumerable<T> interface, 677

IProducerConsumerCollection<T> interface, 939

IQueryable<T> interface

delegates, 620621

query expressions, 708

queryable extensions, 694695

"is a" relationships

abstract members, 361

classes, 388

derivation forms in, 339

"is a kind of" relationships, 257258, 336

is operator

pattern matching example, 156157

pattern matching overview, 365371

positional pattern matching, 369

properties, 369370

recursive pattern matching, 370371

tuples, 368

type, var, and const pattern matching, 366368

types with, 365366

is { } property pattern, 156157

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

compiling, 764766

defining, 754

escaping, 763764

multiple, 766767

origin, 753754

recursive, 762763

states, 757759

syntax, 755

yielding values from, 755762

J

Jagged arrays

defining, 106

element assignment, 108109

length, 110

Java language vs. C#

arrays, 101102

exception specifiers, 518

filenames, 10

generics, 584585

implicit overriding, 347

import directive, 210

inner classes, 328

Main(), 19

syntax similarities, 23

virtual methods, 346

JIT (just-in-time) compiler and jitting

CIL, 980

description, 34

thread synchronization, 920

Join() method

inner joins, 682686

threads, 914

Join operations

inner joins, 682686

outer joins, 688691

overview, 678682

Jump statements

break, 180181

continue, 182184

goto, 184185

lambda expressions, 606

Just-in-time (JIT) compiler and jitting

CIL, 980

description, 34

thread synchronization, 920

K

KeyNotFoundException type, 741

Keys

dictionaries, 728730, 740741

equality, 743744

sorted collections, 746

Keys property, 746

KeyValuePair<TKey, TValue> class, 741

Keywords

contextual, 766

as identifiers, 17

list of, 14

overview, 1315

types, 47

L

Labels for switch statements, 177, 185

Lambda calculus, 608

Lambda expressions

asynchronous, 881887

as data, 616618

deferred execution, 674

expression trees, 616623

filters, 715

internals, 610611

lazy loading, 509510

notes and examples, 605606

outer variables, 611616

overview, 587588, 600601, 604

predicates, 593

purpose, 608

statement, 601604

LambdaExpression expression trees, 623

Language Integrated Query (LINQ)

anonymous types, 695703

collections, 653654

deferred execution, 672676

delegates, 620

extension methods, 395

with IAsyncEnumerable, 875877

parallel queries, 670671, 905911

query expressions. See Query expressions

Language interoperability, 35

Last in, first out (LIFO) collections, 747

LastIndexOf() method, 736

Late binding with metadata, 992

Latency

async/await syntax, 862867

asynchronous example, 856858

description, 814

multithreading for, 816818

synchronous example, 854856

WPF example, 889891

Lazy initialization, 508510

LazyCancellation task continuation option, 834

Leaf asynchronous task-returning method, 883887

Left-associative operators, 125

Left outer joins, 679

Length

arrays, 109110

strings, 6667

Length property, 66

Less than signs (<)

generics, 540

overriding, 464, 466

pointers, 969

relational operators, 150

shift operators, 163164

XML, 33

let clause, 717718

Libraries

BCL. See Base Class Library (BCL)

classes, 472475

creating, 473

dependencies, 10

referencing, 473475

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 directive, 187, 191

Line feeds

escape sequence, 5859

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)

Liskov, Barbara, 753754

List<T> class

overview, 731733

searches, 736738

Listeners for events, 627, 835836

Lists

collections, 728733

linked, 749

searching, 736738

sorted, 745747

Literal values

characters, 57

default, 5051

overview, 4950

strings, 5961

Load() method, 273

Loading

with files, 270273

lazy, 508510

Local variables

anonymous types, 695701

assigning values to, 2425

declaring, 2223

implicitly typed, 8990

scope, 147149

thread synchronization, 917918

types, 23

working with, 25

Localized applications, Unicode standard for, 56

Locals, constant, 137138

lock keyword

thread synchronization, 920925

value types, 432434

Locks

deadlocks, 821823, 929930

thread synchronization, 920925, 931

value types, 432434

Logical operators

Boolean, 151153

overriding, 468

working with, 164167

Lollipops, 395

Long-running tasks, 848849

long type

characteristics, 46

conversions, 72

LongRunning task continuation option

delays, 849

description, 832

TPL performance, 900

Loop variables in lambda expressions, 614616

Loops

for, 170174

foreach, 174175

parallel iterations, 895905

while and do/while, 168170

LowestBreakIteration property, 905

M

Machine code, compilation to, 3435, 979981

Main() method

async, 867

declaring, 1819

description, 196197

Java vs. C#, 19

multiple, 214216

return values and parameters, 214216

__makeref keyword, 17

Managed code, 34

Managed execution, 3435

Manifests in CLI, 986989

ManualResetEvent class, 934937

ManualResetEventSlim class, 934937

Many-to-many relationships in join operations, 679680

Masks, logical operators for, 165

Matching caller variables with parameters, 218

Max() function, 693

MaxDegreeOfParallelism property, 904

MaybeNull attribute, 307, 309

MaybeNullWhen attribute, 307

Me keyword, 268

Mechanism relationships, 388

Members

abstract classes, 357360

base class overriding, 353355

class variables, 262

classes, 262

default interface, 398400

dynamic invocation, 773779, 781782

explicit and implicit implementation, 386390

static. See Static members

MemberwiseClone() method, 364

Memory

boxing, 428

finalizers, 495

generics, 543

multithreading complexity, 821

objects, 261

reference types, 8284

Metadata

attributes, 306, 783784

CIL, 991992

CLI, 35

reflection, 770773

XML, 33

Method groups for delegates, 596

Method invocations, query expressions as, 724725

MethodCallExpression expression trees, 623

MethodImplAttribute, 925

MethodImplOptions class, 925

MethodInfo class

delegates, 598

dynamic invocation, 777

reflection, 788

Methods

anonymous, 600, 606608, 610611

arguments, 201

attributes, 799

call stacks, 216217

called during construction, 348349

casting in, 572573

constraints, 571572

constructors. See Constructors

declaring, 203204

description, 18, 196197

expression bodied, 208

extension, 321322, 344, 394395, 411413

external, 948949

generics, 568573, 779780

instance, 265266

interface refactoring, 401

Main(), 214216

names, 201

namespaces, 198200, 209211

overloading, 231234

overview, 197198

parameters. See Parameters

partial, 330332

passing as arguments, 590592, 596

publish-subscribe pattern, 640

recursion, 229231

refactoring into, 204205

resolution, 238239

return values, 202, 206208

scope, 201

vs. statements, 202203

static members, 315316

strings, 6264

structs, 424

syntax, 18

this keyword, 269270

type inferences, 569571

types, 200201

using directive, 209214

virtual, 346349

Microsoft .NET Framework

assemblies, 40

CLI implementation, 975977

description, 39

garbage collection, 489491

versioning, 4042

Microsoft Silverlight compiler, 976

Min() function, 693

Minus signs (-)

compound assignment, 132

decrement operator, 133

delegates, 632634, 650

identifier names, 16

overriding, 466469

precedence, 124

referent member access, 970

subtraction, 123

unary operator, 122123

Modules

attributes, 784786

CLI, 986989

dependencies, 992

Monitor class

locks, 432

thread synchronization, 918920, 923924

Mono compiler, 976

Mono .NET frameworks, 39

Move() method, 321

MoveNext() method

duck typing, 662

iterators, 758759, 764

MoveNextAsync() method, 874

MTAs (multithreaded apartments), 945

Multicast delegates

description, 625

internals, 636637

publish-subscribe pattern. See Publish-subscribe pattern

MulticastDelegate class

constraints, 558559

internals, 597598, 636637

Multidimensional arrays, 102106, 108

Multiple constraints, 561562

Multiple inheritance

C++, 345

interfaces, 393

Multiple interfaces for single classes, 545546

Multiple Iterators, 766767

Multiple Main() methods, 214216

Multiple .NET frameworks, 3943

Multiple searches in lists, 737738

Multiple selection for query expressions, 722723

Multiple threads synchronization. See Thread synchronization

Multiple type parameters in generics, 549551

Multiplication

binary operator, 123

compound assignment, 132

shift operator, 164

Multithreaded apartments (MTAs), 945

Multithreading

asynchronous tasks. See Asynchronous tasks

atomic operations, 819820

canceling tasks, 843849

deadlocks, 821822

description, 816

disposability of tasks, 849

issues, 819822

jargon, 815816

long-running tasks, 848849

memory model complexity, 821

overview, 813815

performance considerations, 818819

purpose, 816818

race conditions, 820821

Threading class, 850851

Mutable value types, 434

Mutex class, 932933

MutexSecurity class, 932933

Mutual exclusion in deadlocks, 930

N

escape sequence, 5859

new lines, 66

Name/value pairs for dictionaries, 656, 738, 741

Named arguments, 237238

Named parameters

attributes, 794795

changing names of, 237

nameof operator

arguments, 513

properties, 285

working with, 781782

Names

ambiguity, 267268

class definitions, 17

collisions, 198

constant values, 137

constructor parameters, 300

constructors, 294

enums, 439

fields, 281282

identifiers, 1516

indexers, 751

local variables, 24

methods, 197198, 201

scope, 147149

tuples, 95

type parameters, 544

variables, 418

Namespaces

aliasing, 213214

defining, 481484

methods, 198200

nesting, 483

using directive, 6465, 209211

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

classes, 326328

delegates, 594595

generic types, 552553

if statements, 142144

iterators, 762763

namespaces, 210, 483

using directive, 211212

.NET Compact Framework, 976

.NET Core, 975, 977978

.NET frameworks

description, 993

garbage collection, 489491, 983984

multiple, 3943

overview, 3

standard, 4243

versioning, 4042

.NET Micro Framework, 976

Net namespace, 483

.NET Native feature, 993

.NET Standard version, 978979

new modifier in base class overriding, 349353

new operator

arrays, 100, 103

constructors, 294295

objects, 260261

projections, 668669

value types, 426427

Newlines

escape sequence, 5859

preprocessor directives, 186

variations, 66

NGEN tool, 980

No preemption condition in deadlocks, 930

NodeType property expression trees, 623

Non-nullable reference type properties, 303306

None task continuation option, 831

Normal continuation, 829

Normal form for parameters, 227

Normalized data, 682

Not a Number (NaN) value, 131

NOT operators

inequality, 150151

logical, 153

Notifications for thread synchronization, 928929

NotImplementedException type, 248

NotNull attribute, 307

notnull constraints, 560

NotNullIfNotNull attribute, 307308

NotNullWhen attribute, 307308

NotOnCanceled task continuation option, 833

NotOnFaulted task continuation option, 832

NotOnRanToCompletion task continuation option, 832

nowarn preprocessor directive option, 190191

NuGet packages

invoking, 477479

references, 475477

referencing, 473

Null character escape sequence, 57

Null-coalescing operator, 157160

Null-conditional operator

dereferencing operations, 513

null checks, 86, 630

thread synchronization, 928

working with, 158161

Null-forgiving operator (!), 160161, 634

null modifier, 308309

null references, dereferencing, 85

null values

checking for, 8586

collections, 753

dereferencing, 87

pointers, 964965

programming with, 155157

publish-subscribe pattern, 630632

strings, 6970

types allowing, 8485

Nullable attributes, 306308

#nullable directive, 88, 187, 193

nullable modifier

reference types, 71

strings, 70

type declarations, 8485

Nullable reference types

default values, 548

nullable modifier, 84

overview, 7071, 8789

preprocessor directives, 193

Nullable values

array initial values, 104

default values, 548

description, 86

example, 538539

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

floating-point, 4749

hexadecimal notation, 5254

integers, 4647

literal values, 4950

round-trip formatting, 5455

O

Object class

derivation from, 363365

dynamic objects, 805806

Object-oriented programming

encapsulation, 257

inheritance, 257259

overview, 256257

polymorphism, 259

Objects. See also Classes

associated data, 314

CTS, 990

defined, 260

dynamic programming, 801802

expression trees, 618619

filtering, 666667

identity vs. equality, 456460

initializers, 296297

member overriding, 451464

resurrecting, 507508

ObsoleteAttribute, 797, 799800

OfType<T>() operator, 693

One-to-many relationships

example, 680681

inner joins, 686688

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

assignment, 2425

associativity, 124125

binary, 123124

bitwise, 162167, 181182

characters in arithmetic operations, 127128

compound assignment, 132, 468

concatenation, 126127

conditional, 154155

constant expressions and locals, 137138

constraints, 567568

decrement, 133137

delegates, 633634

description, 121

evaluation, 125

floating-point equality, 129132

increment, 133

logical, 151153, 164167

with null, 155157

null-coalescing, 157158

null-conditional, 158161

null-forgiving, 160161

overriding, 464472

overview, 122

precedence, 124125, 194

relational and equality, 150151

shift, 163164

special floating-point characteristics, 128129

thread-safe, 137

unary, 122123

Optional parameters, 234238

OR operations

bitwise operators, 164165

constraints, 568

enums, 444445

logical operators, 151152

orderby clause, 716717

OrderBy() method, 676678

OrderByDescending() method, 678

Ordering collections, 735736

out parameters

conversions, 78

properties, 291

out type parameter modifier, 575577

Outer joins, 679, 688691

Outer variables in lambda expressions, 611616

OutOfMemoryException type, 514, 520

Output, console, 2833

Output parameters, 220223

Overflow, buffer

C# vs. C++, 109110

managed execution, 986

type safety, 35, 984

unsafe code, 962

Overflow of integers, 528530

OverflowException type, 73, 529

Overloading

constructors, 298300

methods, 231234

override keyword, 349351

Overriding

assignment operators, 468

Base class. See Base class overriding

binary operators, 466467

comparison operators, 464465

conversion operators, 470472

Equals(), 455464

GetHashCode(), 453455, 463464

logical operators, 468

methods, 349351

object members, 451464

operators, 464472

ToString(), 452453

unary operators, 468470

P

P/Invoke. See Platform Invoke (P/Invoke)

Packages, invoking, 477479

Pair<T> type

iterators, 760, 764

struct vs. class, 763

Parallel class, 897898

Parallel iterations

loops, 895905

overview, 895

performance, 899900

PLINQ queries, 905911

Parallel LINQ (PLINQ), 814

canceling queries, 908911

parallel queries, 905911

running queries, 670671, 905908

Parallel loops

breaking, 904905

canceling, 901903

exception handling, 900901

for, 895898

foreach, 898899

options, 903904

performance, 899900

Parallel programming, 818

ParallelEnumerable class, 670, 906907

ParallelLoopResult class, 905

ParallelLoopState class, 905

ParallelOptions class, 904

ParallelQuery<T> class, 911

ParameterExpression expression trees, 623

Parameterized generic types, 539540

Parameters

anonymous methods, 607608

arrays, 226229, 552

catch blocks, 516

constraints. See Constraints

constructors, 294, 299300

declaring, 205

events, 645

extension methods, 322

finalizers, 495

generics, 542, 544545, 549551

in, 223

indexers, 752

lambda expressions, 606

Main(), 214216

matching caller variables with, 218

method resolution, 238239

methods, 197, 201

optional, 234238

out, 220223

reference types, 218220

return by reference, 223225

statement lambdas, 602604

types, 949951

value, 217220

Parent types, 258, 336

Parentheses ()

casts, 72, 339

collection initializers, 655

declaration lists, 205

lambda expressions, 603

logical operators, 152

operator precedence, 125

query expressions, 723

tuples, 92

Parse() method

conversions, 76, 79

enum, 442

FlagsAttribute, 796797

metadata, 772773

Parsing types, 7779

Partial classes

defining, 329330

methods, 330332

Partial interface refactoring, 405

Partial methods

description, 208

interface refactoring, 405

PascalCase

description, 1516

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

delegates, 509, 597598, 604

instances, 419

method return values, 202

methods as arguments, 590592, 596

null values, 85

out parameters, 220

read-only references, 223

this keyword, 270, 426

values to methods, 82, 217

variables by reference, 219

variables to methods, 197

Pattern matching

is operator, 365371

with null, 156

polymorphism, 373

positional, 369

properties, 369370

recursive, 370371

switch statements, 179, 371372

tuples, 368

types, var, and const, 366368

Peek() method, 747

Percent signs (%)

compound assignment, 132

overriding, 466, 468

precedence, 124

remainder operation, 123

Performance

CLI, 985986

hash codes, 454

multithreading, 818819

parallel iterations, 899900

Periods (.)

fully qualified method names, 198

nested namespaces, 210, 483

null-conditional operator, 158

Pi calculations, 895898

Platform interoperability

delegates, 971972

overview, 947948

P/Invoke, 948960

pointers and addresses, 960970

Platform Invoke (P/Invoke)

description, 948

error handling, 953955

external functions, 948949, 956958

function pointers, 960

parameter data types, 949951

references, 951952

SafeHandle, 955956

sequential layout, 952953

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

delegates, 633634, 650

increment operator, 133

overriding, 464, 466469

precedence, 124

strings, 126127

unary operator, 122123

Pointers

assigning, 964965

declaring, 963964

dereferencing, 968970

fixing data, 965967

function, 960

P/Invoke, 951952

vs. ref, 951

referent member access, 970

stacks, 967968

unsafe code, 961963

Polling tasks, 826828

Polyfill code, 526

Polymorphism

abstract classes, 361363

interfaces, 380384

operational, 232

overview, 259

pattern matching, 373

with protected interface members, 406411

Pools

temporary, 419

threads, 816, 824, 850851

Pop() method, 534537, 747748

Positional pattern matching, 369

Positive infinity value, 131

Positive zero value, 132

Postfix operators, 134136

#pragma directive, 187188, 190191

Precedence of operators, 124125, 194

Precision of floating-point types, 4748, 128129

Predefined attributes, 797

Predefined types, 45

Predicates

delegates, 621, 666667

filters, 715

lambdas, 593

PreferFairness task continuation option, 832

Prefix operators, 134136

Prefixes for hexadecimal notation, 53

Preprocessor directives

excluding and including code, 188

line numbers, 191

list of, 186188

nullable references, 193

purpose, 186

symbols, 189

visual code editors, 191193

private access modifier

description, 481

inheritance, 341342

interface refactoring, 402

nested classes, 328

private internal access modifier, 481

Private members for information hiding, 274276

private protected access modifier, 402403

Procedural programming, 195

Process class

multithreading, 815

notifications, 885

Processes, description, 815

ProcessExit events, 503507

Processor-bound latency, 814

Projections

anonymous types, 698699

collections, 668669

query expressions, 706, 708711

Projects

creating, 910

invoking, 477479

referencing, 473475

Properties

attributes, 783787

automatically implemented. See Automatically implemented properties

calculated, 287289

declaring, 277279

getters and setters, 289291

guidelines, 281283

interface refactoring, 401

internals, 291293

lazy loading, 508

nameof operator, 285

overriding, 346347

overview, 276277

pattern matching, 369370

read-only and write-only, 286287

retrieving, 771772

static, 318319

strings, 6670

structs, 425426

unallowed parameter values, 291

with validation, 283285

PropertyChanged event, 782

PropertyInfo class

attributes, 788, 790

dynamic invocation, 777

protected access modifier

description, 481

inheritance, 342344

interface refactoring, 402

protected interface members, encapsulation and polymorphism with, 406411

protected internal access modifier, 480481

public access modifier

description, 481

interface refactoring, 402

on type declarations, 479480

Public constants, 324

publish command, 1112

Publish-subscribe pattern

delegate invocation, 629632, 634636

delegate operators, 633634

encapsulation, 641

error handling, 637640

hooking up publishers and subscribers, 628629

method returns and pass-by-reference, 640

multicast delegate internals, 636637

null checks, 630632

publishers, 627628

subscriber methods, 626627

Pulse() method, 920

Pure virtual functions, 361

Push() method, 534537, 747

Q

Quantums, 817

Queries, parallel, 670671, 905911

Query continuation clauses, 721722

Query expressions

deferred execution, 711715

distinct members, 723724

filters, 715716

grouping, 718721

introduction, 706708

as method invocations, 724725

overview, 705706

projections, 708711

query continuation clauses, 721722

sequences, 722723

sorting, 716718

tuples, 710711

Queryable class

delegates, 620

queryable extensions, 694695

Question marks (?)

command-line option, 783

conditional operators, 154155

null-coalescing operator, 157158

null-conditional operators, 158160

nullable modifier, 70, 85

Queue<T> class, 658, 748

Queues

collections, 748

finalization, 298, 500501

thread synchronization, 920, 939

R

escape sequence, 58

newlines, 66

Race conditions

increment and decrement operators, 137

multithreading, 820821

thread synchronization, 916

Range type, 112

Range variables in query expressions, 707708, 721

Ranges for arrays, 101, 111112

Rank members, 114115

Ranks of arrays, 101102

Read() method

console input, 27, 845

interlocks, 927

Read-only automatically implemented property

declaring, 325326

reference-type, 305306

Read-only pass by reference parameters, 223

Read-only properties

defining, 286287

strings, 67

Read-only structs, 423424

Read/write non-nullable reference type properties, 304305

Readability

vs. comments, 3233

delegates, 594

digit separators, 52

enums, 437

generics, 543

if statements, 183

importance, 203

indentation, 146

methods, 18

parentheses, 125

refactoring for, 204205

switch statements, 179

whitespace, 2122

ReadAllTextAsync() method, 874

ReadAsync() method, 864

ReadKey() method, 27

ReadLine() method

console input, 2627

invoking, 197198

readonly modifier, 324326

Recursion

infinite, 231

iterators, 762763

methods, 229231

pattern matching, 370371

Redimensioning arrays, 114

Reentrant locks, 930

ref parameters for properties, 291

Refactoring

classes, 336337

interface features, 401405

into methods, 204205

ReferenceEquals() method

description, 364

with null, 156

objects, 456458

References and reference types

array initial values, 104

assemblies, 472479

covariance, 576

default values, 548

garbage collection, 491493

generic instantiation, 583584

identity vs. equality, 456459

invoking, 477479

libraries, 473475

new operator, 426

non-nullable properties, 303306

NuGet packages, 475477

overview, 8184

parameters, 218220

vs. pointers, 951952

vs. value, 419421

Referent types

member access, 970

pointers, 963964

Reflection

description, 769

dynamic programming, 801802

generics, 779781

member invocation, 773779

metadata, 770773, 992

overview, 770771

Reflection class

delegates, 598

metadata, 772

__reftype keyword, 17

__refvalue keyword, 17

#region directive, 187, 191193

Register() method, 846

Registration

assemblies, 989

finalization activities, 503504

token cancellation, 846

RegularExpressions class, 199

Relational operators, 150151

ReleaseHandle() method, 956

Remainder operations

binary operator, 123

compound assignment, 132

Remove() method

delegates, 558, 634, 650651

dictionary elements, 741

lists, 733

strings, 69

RemoveAt() method, 733

Replace() method, 64, 69

Representation errors for floating-point types, 128129

ReRegisterFinalize() method, 507508

Reserved keywords, 15, 17

Reset events for thread synchronization, 934937

Reset() method, 659

Resize() method, 114

Resolution of methods, 238239

Resource cleanup

description, 493

deterministic finalization, 262, 496500

exception propagating from constructors, 507

finalizers, 493496

forcing, 503507

garbage collection, finalization, and IDisposable, 500501

guidelines, 501502

resurrecting objects, 507508

Results, operator, 122

Resurrecting objects, 507508

Rethrowing exceptions, 517518, 522523, 527530

Return attributes, 785786

Return by reference parameters, 223225

return statement, 206207

Return values

async, 864, 868870

asynchronous void methods, 877881

declaring, 206208

Main(), 214216

methods, 197198, 202

ReadLine(), 2627

Reverse accessing arrays, 100

Reverse() method

arrays, 112

collections, 693

strings, 116117

Right-associative operators, 125

Right outer joins, 679

Root references in garbage collection, 490

Round-trip formatting, 5455

Rounding floating-point types, 48, 128129

Run() method

asynchronous tasks, 825826

preference for, 847848, 914

RunContinuationsAsynchronously task continuation option, 834

Running source code, 34

RunProcessAsync() method, 883

Runtime

CLI, 982984

defined, 35

description, 35

purpose, 974

Runtime callable wrappers (RCWs), 945

Runtime.InteropServices.COMException type, 514

RuntimeBinderException type, 802, 804, 810

S

SafeHandle class, 955956

sbyte type, 46

Schedulers for tasks, 824, 887889

Scope

captured outer variables, 612

code blocks, 147149

methods, 201

SDK (software development kit), 3

sealed access modifier

base class overriding, 353354

interface refactoring, 404

sealed classes, 345

Sealed classes, 345

Searching

dictionaries, 741

lists, 736738

Security

buffer overflows, 110

code access, 35

exposing holes in, 962963

hash codes, 454

obfuscation, 36

SEHException type, 514, 519

select clauses in query expressions, 707708

Select() method

anonymous types, 698699

LINQ queries, 906

outer joins, 691

projections, 668669

Selecting into anonymous types, 698699

SelectMany() method

outer joins, 688691

query expressions, 722723

Semantic relationships, 388

Semaphore class

reset events, 937938

thread synchronization, 934

SemaphoreSlim class, 937938

Semicolons (;)

ending statements, 20

for loops, 171172

preprocessor directives, 189

SequenceEquals() operator, 693

Sequences in query expressions, 722723

Sequential invocation, 634636

Sequential layout, 952953

Serializable exceptions, 526

SerializableAttribute, 526

SerializationInfo type, 526

set keyword for properties, 278279

Set() method for thread synchronization, 934

SetResult() method, 885

setters

access modifiers, 289291

properties, 67, 278279

SetValue() method, 777

Shared collection states, 660

Shared Source compiler, 976

Shift operators, 163164

Short-circuiting operators

asynchronous methods, 868

conditional, 154

logical, 152

null-coalescing, 157

null-conditional expressions, 159

short type, 46

SignalAndWait() method, 933

Signatures

constructors, 299300

deconstructors, 311

interfaces, 396

methods, 147, 231234

Signed numbers, 162163

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

Size of arrays, 103105, 114

Sleep() method, 850851

Software development kit (SDK), 3

Sort() method

arrays, 112

collections, 734735

lists, 733

Sorted collections, 745747

SortedDictionary<TKey, TValue> class, 745747

SortedList<T> class, 745747

Sorts

bubble, 588602

collections, 734735

query expressions, 716718

standard query operators, 676678

Source code

compiling, 34, 1011, 3435

creating, 34

debugging, 89

editing overview, 34

editing with dotnet CLI, 46

editing with Visual Studio 2019, 68

essential, 1213

running, 34

Special floating-point characteristics, 128129

Specialized types, 258259

Splitting statements across lines, 20

Square brackets ([])

arrays, 101103, 108

attributes, 783784

indexers, 750

null-conditional operators, 158160

Stack class, 534537

Stack unwinding, 217

Stack<T> class

collections, 658659, 747

declaring, 581, 779

generics, 542543

StackOverflowException type, 248, 514, 520

Stacks

collections, 747

exception handling, 521

methods, 216217

pointers, 967968

rethrowing exceptions, 517518

thread synchronization, 939

for undo operations, 540542

value types, 419

Stand-alone executables, 1112

Standard query operators

anonymous types, 695703

collections, 653654

deferred execution, 672676

element counting, 671672

example code, 691692

filters, 666667

join, 678691

list of, 693

overview, 663666

parallel queries, 670671

projections, 668669

queryable extensions, 694695

sorting, 676678

Start() method, 406407, 826, 829

StartNew() method, 847849, 914

StartsWith() method, 63

Statement lambdas, 601604

Statements

delimiters, 1920

vs. methods, 202203

multiple on one line, 20

splitting across lines, 20

without semicolons, 20

States

collections, 660

iterators, 757759

STAThreadAttribute, 945

Static classes, 319321

Static compilation vs. dynamic programming, 807808

static keyword, 311313

Static members

associated data, 314

constructors, 316318

fields, 311314

interface refactoring, 401

methods, 315316

overview, 311

properties, 318319

strings, 6263

Stop() method, 905

Store() method, 270

Storing

with files, 270273

reference types, 419421

value types, 418419

StreamingContext type, 526

StreamReader class

async methods, 864

data retrieval, 273

Streams, asynchronous, 870874

StringBuilder type, 69, 557

Strings

as arrays, 115117

comparing, 56

concatenating, 61, 126127

conversions, 7677

description, 59

directives, 6465

enum conversions, 441443

format, 2930

formatting, 6566

immutability, 26, 6769, 968970

vs. integers, 240241

interpolation, 2830, 6162

length, 6667

literal values, 5961

locks, 924925

methods, 6264

modifying, 69

newlines, 66

null values, 6970

nullable modifier, 70

nullable reference types, 71

properties, 6670

reversing, 116117

void values, 69

Strong references in garbage collection, 491493

StructLayoutAttribute, 952953

structs

vs. classes, 763

constraints, 560561

declaring, 422423

generics, 544545

initializing, 424426

readonly, 423

unmanaged, 952953

Structural equality of delegates, 608609

Structured programming, 195

Subscribers

delegate invocation, 629632

events, 645

exception handling, 637640

hooking up, 628629

methods, 626627

Subscriptions. See Publish-subscribe pattern

Subtraction

binary operator, 123

compound assignment, 132

decrement operator, 133

unary operator, 122123

Subtypes, 258, 336

Suffixes

attributes, 786

literal values, 5152

numeric types, 46

Sum() function, 693

Super types, 258, 336

SuppressFinalize() method, 500501

Surrogate pairs, 57

switch statements

goto in, 184185

overview, 141

pattern matching, 371372

working with, 176179

Symbols, preprocessor, 189

Synchronization

lock statement, 432434

thread. See Thread synchronization

Synchronization context with task schedulers, 887889

Synchronized method, 925

Synchronous delegates, 824

Syntax

identifiers, 1516

iterators, 755

keywords, 1315, 17

Main(), 1819

methods, 18

tuples, 92

type definitions, 17

variables, 2223

System.Action delegates, 592594

System.ApplicationException type, 247, 514

System.ArgumentNullException type, 247, 285, 513514

System.ArithmeticException type, 248

System.Array class, 113114

System.Array.Reverse() method, 112, 116117

System.ArrayTypeMismatchException type, 248

System.Attribute class, 787

System.AttributeUsageAttribute class, 793795, 797

System.Boolean class, 56

System.Char class, 56

System.Collections.Generic class

linked lists, 749

stacks, 542543

System.Collections.Generic.ICollection<T> interface

collection initializers, 654655

element counting, 671672

members, 730731

System.Collections.Generic.IEnumerable<T> interface. See IEnumerable<T> interface

System.Collections.Generic.IEnumerator<T> interface, 658662

foreach loops, 658662

iterators, 755756, 764

yield statement, 767

System.Collections.Generic.List<T> class, 736738

System.Collections.Generic.Stack<T> type, 658659

System.Collections.Generics namespace, 199

System.Collections.IEnumerable interface, 760

System.Collections.IEnumerator interface, 658662

System.Collections.Immutable library, 939

System.Collections.Stack class, 534537

System.ComponentModel class, 953

System.Console class

input methods, 2627, 197

newlines, 59, 66

output methods, 19, 2833, 197

round-trip formatting, 5455

System.Convert type, 76

System.Data namespace, 199

System.Delegate class

assignment operators, 634, 650

constraints, 558559

internals, 597598, 636637

System.Diagnostics class

debugging with, 799

notifications, 885

nullable attributes, 306309

processes, 815

System.Drawing class, 199

System.Dynamic.DynamicObject class, 808811

System.Dynamic.IDynamicMetaObjectProvider interface, 808

System.Enum class, 439, 442

System.Environment class

command-line arguments, 19, 216

new lines, 66

thread synchronization, 933

System.EventArgs class, 645647

System.EventHandler<T> class, 647648, 650651

System.Exception type, 511512, 514

catch blocks, 518520

description, 247

System.FormatException type, 244, 247

System.Func delegates, 592594

System.GC class

finalization, 500

finalizers, 496

garbage collection timing, 490

resource cleanup, 506508

System.Index type, 112

System.IndexOutOfRangeException type, 247

System.IntPtr class, 951, 963

System.InvalidCastException type

description, 247

generics, 543

using, 472

System.InvalidOperationException type. See InvalidOperationException type

System.IO class, 199, 520

System.IO.DirectoryInfo class

extension methods, 321

inner joins, 682

System.IO.FileAttributes class, 443

System.IO.FileInfo class

inner joins, 682

projections, 668669, 717718

query expressions, 710

System.IO.FileStream class, See FileStream class

System.Lazy<T> class, 509510

System.Linq.Async NuGet package, 875

System.Linq class, 199, 684688

System.Linq.Enumerable class, See Enumerable class

System.Linq.Extensions.Enumerable class, 677

System.Linq.ParallelEnumerable class, 670, 906907

System.Linq.Queryable class

delegates, 620

queryable extensions, 694

System.MulticastDelegate class

constraints, 558559

internals, 597598, 636637

System namespace, 199

System.Net namespace, 483

System.NotImplementedException type, 248

System.NullReferenceException type. See NullReferenceException type

System.Object class

derivation from, 363365

dynamic objects, 805806

System.ObsoleteAttribute, 797, 799800

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, 805806

System.Runtime.CompilerServices.CompilerGeneratedAttribute, 293

System.Runtime.ExceptionServices class, 517

System.Runtime.InteropServices class

SafeHandle, 955956

unmanaged exceptions, 519

System.Runtime.Serialization type, 526

System.Security.AccessControl.MutexSecurity class, 932933

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, 850851

System.Threading.CancellationToken class. See CancellationToken class

System.Threading.Interlocked class, 137, 926928

System.Threading.ManualResetEvent class, 934, 937

System.Threading.Monitor class

locks, 432

thread synchronization, 918920, 923924

System.Threading.Mutex class, 932933

System.Threading.Tasks class, 199, 823, 914

System.Threading.Tasks.TaskCanceledException type, 846847

System.Threading.Tasks.TaskScheduler class, 887

System.Threading.Thread class, 823

System.Threading.WaitHandle class, 933934

System.Timers class, 944

System.Type class

generic parameters, 780

metadata, 770771

type parameters, 779

System.ValueTuple class, 9698, 550551

System.ValueType class, 427, 771

System.Web class, 199, 483

System.Windows class, 200

System.Windows.Forms class, 944

System.Xml namespace, 200

T

escape sequence, 58

Tabs escape sequence, 58

Task-based Asynchronous Pattern (TAP), 823

async/await syntax, 861867, 890891

async return types, 869870

asynchronous lambdas and local functions, 881887

asynchronous streams, 870874

await operator, 892893

await using statement, 874875

complexity, 859861

description, 814

high-latency example, 856858

IAsyncDisposable, 874875

LINQ with IAsyncEnumerable, 875877

overview, 853

return types, 877881

synchronization context, 887889

synchronous issue example, 854856

task schedulers, 887889

ValueTask<T> returns, 861867

Windows UI, 889891

Task class, 823

asynchronous tasks, 825826

thread synchronization, 914

timers, 944

Task.Factory class, 847848, 914

Task Parallel Library (TPL)

asynchronous complexity, 859861

asynchronous example, 856858

cooperative cancellation, 843847

description, 814

for loop parallel iterations, 897

foreach loop parallel iterations, 898899

performance, 899900

purpose, 823824

thread synchronization, 914

threads pools, 851

TaskCanceledException type, 846847

TaskCompletionSource<T> class, 884885

TaskContinuationOptions enums, 831834

Tasks

asynchronous. See Asynchronous tasks

canceling, 843849

continuation, 829836

description, 816

disposability of, 849

exceptions, 836840

long-running, 848849

polling, 826828

schedulers, 824, 887889

TaskScheduler class, 887

TaskScheduler property, 904

Temporary storage pools

reference types, 421

value types, 419

TemporaryFileStream class, 495497

Ternary operator, 154

Text class

description, 199

type parameters, 557

ThenBy() method, 676678

ThenByDescending() method, 678

this keyword

class members, 266270

constructors, 300301

extension methods, 322

locks, 924925

nested classes, 328

static methods, 316

Thread class, 823, 850851

Thread pools

description, 816

multithreading, 823

Thread-safe code and operations

delegate invocation, 632

description, 816, 917

event notifications, 929

increment and decrement, 137

Thread synchronization

best practices, 929931

COM threading model, 945

concurrent collection classes, 938939

deadlocks, 929930

event notification, 928929

Interlocked class, 926928

local variables, 917918

locks, 920925, 931

monitors, 918920

Mutex class, 932933

need for, 931

overview, 913914

purpose, 914917

reset events, 934937

semaphores, 937938

task return, 922923

thread local storage, 939943

timers, 943944

volatile fields, 926

WaitHandle class, 933934

Threading class, 850851

ThreadLocal<T> type, 940941

ThreadPool type, 850851

Threads

description, 816

exceptions, 840843

local storage, 939943

multithreading. See Multithreading

pools, 850851

synchronization. See Thread synchronization

ThreadStaticAttribute, 941942

Throw() method, 517518, 521

throw statements, 249251, 512

ThrowIfCancellationRequested() method, 847

Throwing exceptions, 512

in catch blocks, 521

error reporting, 249251

error trapping, 241

stack information in, 517518

Tildes (~)

complement operator, 167

finalizers, 494

list searches, 736

overriding, 468

Time slices, 817818

Timers class, 944

Timers for thread synchronization, 943944

ToArray() method, 674675

ToAsyncEnumerable() method, 876877

ToCharArray() method, 116

ToDictionary() method, 674675

ToEnumerable() method, 876

ToList() method, 674675

ToLookup() method, 674675

ToLower() method, 64

Torn reads, 917

ToString() method

conversions, 77

description, 364

enum, 441, 447

FlagsAttribute, 796797

overriding, 452453

Total ordering collections, 735736

ToUpper() method, 64

TPL. See Task Parallel Library (TPL)

Trace() method, 799

TRACE preprocessor identifier, 799

Trapping errors, 241246

Trim() method, 64

TrimEnd() method, 64

TrimStart() method, 64

TrimToSize() method

lists, 731733

queues, 748

True/false evaluations, 55

true operator, overriding, 468470

Try blocks, 242244

TryParse() method

attributes, 791793

conversions, 7779

dynamic invocation, 777

enum, 442

Tuples

declaring and assigning, 9296

generics, 550552

GetHashCode() and Equals() overriding, 463464

groups, 720721

pattern matching, 368

projections, 669

query expressions, 710711

return values, 207208, 222223

System.ValueTuple type, 9698

Two-dimensional arrays, 102, 104105

Two's complement notation, 162163

Type checking, 984

Type class

generic parameters, 779780

metadata, 770771

type parameters, 779

Type parameters

cascading, 552

constraints. See Constraints

contravariance, 577579

covariance, 575577

generics, 542, 545

lists, 205

multiple, 549551

names, 544

null modifier, 308309

obtaining, 780781

type of, 779

Type safety, 537

anonymous types, 700701

CLI, 984

generics, 543

managed execution, 35

typeof() method

attributes, 789

locks, 924925

reflection, 771773

Types

anonymous. See Anonymous types

arrays. See Arrays

Boolean, 5556

character, 56

conversion overview, 7277

CTS, 990

decimal, 49

declarations, access modifiers on, 479480

default, 5052

definitions, 17

delegates, 590594, 647

description, 23

dynamic, 803

exceptions, 511514

floating-point types, 4749

generics, 540

hardcoding values, 50

hexadecimal notation, 5254

implicitly typed local variables, 8990

integers, 4647

lambda expressions, 605

local variables, 23

methods, 197198, 200201

nested, 552553

null allowed, 8485

null checks, 8586

nullable reference, 8789

nullable values, 86

overview, 45

parameters, 949951

parsing, 7779

pattern matching, 366368

reference, 8184

retrieving, 771772

return values, 206208

strings. See Strings

tuples, 9298

Unicode standard, 56

unmanaged, 963

from unmanaged structs, 952953

value. See Values and value types

verifying, 365366

well-formed. See Well-formed types

U

u escape sequence, 58

uint type, 46

ulong type, 46

Unary expression trees, 618619

Unary operators

overriding, 468470

plus and minus, 122123

UnauthorizedAccessException type, 527, 901

Unboxing operation, 428431, 434436

Unchecked conversions, 7375, 528530

unchecked keyword, 75, 530

Uncompress() method, 379

#undef directive, 187, 189

Underscores (_)

digit separators, 52

field names, 281

identifier names, 1617

variable names, 24

VB line continuation character, 20

Undo operations

generics for, 540542

stacks for, 534537

Unhandled exceptions

description, 241

parallel loops, 900901

reporting, 520

tasks, 836840

threads, 840843

UnhandledException type, 841

Unicode standard

character representation, 5658

escape sequence, 58

localized applications, 56

Union() operator, 693

Unity .NET frameworks, 39

Unmanaged code and types

buffer overflows, 109

calls into, 948949

constraints, 559560

description, 34

exceptions, 519

guidelines, 960

parameters, 949951

performance, 985986

pointers, 951, 960, 963

resource cleanup, 503506

stack allocation, 967

structs, 952953

UnobservedTaskException type, 840

Unreachable end points in methods, 206207

Unsafe code, 947

delegates, 971972

platform interoperability. See Platform interoperability

pointers, 961963

unsafe modifier, 961962

Unwrap() method, 859860

UserName class, 933

ushort type, 46

using directive

aliasing, 213214

deterministic finalization, 496500

namespaces, 209211

nested, 211212

strings, 6465

using static directive

strings, 6465

working with, 212213

V

Validation, properties with, 283285

value keyword for properties, 278279

Values and value types

boxing, 428436

CTS, 990

description, 418

enums. See enum values

generic instantiation, 582583

hardcoding, 50

immutable, 424

inheritance and interfaces, 427

from iterators, 755762

lock statement, 432434

new operator, 426427

overview, 8182, 417

parameters, 217218

vs. reference, 419421

structs, 422427

variables, 418419

Values property for sorted collections, 746

ValueTask<T> class, 864, 867869, 876877

ValueTuple class, 550551

ValueType class, 427, 771

var keyword

pattern matching, 366368

type declarations, 90

Variable parameters, defining index operators with, 752

Variables

anonymous types, 695701

copying, 418419

declaring, 2324

description, 2223

for loops, 170

foreach loops, 174

immutable, 26

implicitly typed local, 8990

instance fields, 262265

lambda expressions, 611616

parameters, 197

query expressions, 707708, 721

reference types, 84, 419421

scope, 147149

thread synchronization, 917918

tuples, 9296

value types, 82, 418419

working with, 25

Variadic generic types, 552

Variance. See Contravariance; Covariance

Variants, 90

Verbatim strings

interpolation, 6162

working with, 5960

Versioning

C# 8.0 and later, 398400

encapsulation and polymorphism with protected interface members, 406411

.NET frameworks, 4042

overview, 396397

pre C# 8.0, 397398

refactoring features, 401405

Vertical bars (|)

bitwise operators, 164

compound assignment, 167

logical operators, 151152

overriding, 466, 468

Vertical tabs escape sequence, 58

Virtual abstract members, 357360

Virtual Execution System (VES)

CLI, 982

description, 994

managed execution, 34, 974

runtime, 35

Virtual functions in C++, 361

Virtual methods

overridden, 355356

overriding, 346349

virtual modifier

base class overriding, 346349

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 code editors, 191193

Visual Studio 2019

CLI, 34

code building and executing, 13

debugging with, 9

NuGet references, 476477

preprocessor directives, 192193

project and library references, 474475

working with, 34, 68

void type

asynchronous method returns, 877880

partial methods, 332

pointers, 969

return values, 207

strings, 69, 7172

Volatile fields, 926

volatile modifier, 926

W

Wait() method

asynchronous requests, 860

asynchronous tasks, 826

reset events, 934, 936937

WaitAll() method

asynchronous tasks, 826

thread synchronization, 933

WaitAny() method

asynchronous tasks, 826

thread synchronization, 933

WaitForPendingFinalizers() method, 496, 506

WaitHandle class, 933934

WaitOne() method, 934, 936

#warning directive, 187, 189190

Warnings

method overriding, 349

preprocessor directives, 186191

Weak references in garbage collection, 491493

Web class, 199, 483

Well-formed types

assembly references, 472479

encapsulation, 479481

garbage collection, 489493

lazy initialization, 508510

namespaces, 481484

overriding object members, 451464

overriding operators, 464472

overview, 451

resource cleanup. See Resource cleanup

XML comments, 485489

Where() operator, 666667, 672676

while loops, 139, 168170

Whitespace

overview, 2122

in strings, 60

trimming, 284

Win32Exception() method, 953955

Windows class, 200

Windows Forms, 889, 944

Windows Presentation Foundation (WPF)

description, 977

high-latency example, 889891

Windows UI applications, 889891

WithCancellation() method, 911

Work stealing, 899

WPF (Windows Presentation Foundation)

description, 977

high-latency example, 889891

Wrapped exceptions, 246, 527530

Wrappers with API calls, 959

Write() method

console output, 2930

invoking, 197198

newlines, 59, 66

strings, 62

Write-only properties, 286287

WriteLine() method

console output, 2930

invoking, 197198

newlines, 59, 66

round-trip formatting, 5455

strings, 62

X

x escape sequence, 58

Xamarin compiler, 976, 978

Xamarin .NET frameworks, 39

XAML (Extended Application Markup Language), 977

xcopy deployment, 989

XML (Extensible Markup Language)

binding elements, 806807

comments, 485489, 770

delimited comments, 32

documentation files, 487489

namespace, 200

overview, 33

reflection, 770

single-line comments, 32

XmlSerializer class, 771

XOR (exclusive OR) operators

bitwise, 164165

logical, 152153

Y

yield statements, 15n

contextual keyword, 766

requirements, 767768

yield break, 763764

yield return, 755756, 760762

Yielding values from iterators, 755762

Z

Zero-based arrays, 99100

Zeros

division by, 131

floating-point types, 132

Zip() method, 875

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.32.154