Index

Operators

- (minus sign)

arithmetic subtraction operator, 9192

delegate operator, 551552

precedence, 92

subtraction operator, overloading, 397399

unary operator, 9091

() (parentheses)

for code readability, 9394

grouping operands and operators, 9394

guidelines, 94

_ (underscore)

in identifier names, 7

line continuation character, 11

in variable names, 15

{ } (curly braces)

formatting code, 13

forming code blocks, 114116

in methods, 9, 1011

omitting, 116

as string literals, 54

@ (at sign)

coding verbatim strings, 48

inserting literal backslashes, 49

keyword prefix, 8

+ (plus sign)

addition operator, overloading, 397399

arithmetic binary operator, 9192

with char type data, 96

concatenating strings, 95

delegate operator, 551552

determining distance between two characters, 96

with non-numeric operands, 95

precedence, 92

unary operator, 9091

+= (plus sign, equal)

binary/assignment operator, 399

delegate operator, 550552

-= (minus sign, equal)

binary/assignment operator, 399

delegate operator, 550552

- (hyphens), in identifier names, 7

__ (two underscores), in keyword names, 8

; (semicolon), ending statements, 67, 11

.... (periods), download progress indicator, 779

" " (double quotes), coding string literals, 48

[ ] (square brackets), array declaration, 7274

(backslashes), as literals, 49

$ (dollar sign), string interpolation, 48

$@ (dollar sign, at sign), string interpolation, 50

< > (angle brackets), in XML, 25

& (ampersand) AND operator, 131, 132

&& (ampersands) AND operator, 121

= (equal sign) assignment operator, 16, 118

== (equality operator), C++ vs. C#, 118

assigning variables, 16

definition, 16

precedence, 92

... (ellipsis) binary/assignment operator, 399

*= (asterisk, equal sign) binary/assignment operator, 399

%= (percent sign, equal) binary/assignment operator, 399

/= (slash, equal) binary/assignment operator, 399

&= (ampersand, equal sign) compound assignment operator, 133134

^= (caret, equal sign) compound assignment operator, 133134

|= (vertical bar, equal sign) compound assignment operator, 133134

?: (question mark, colon) conditional operator, 123124

-- (minus signs) decrement operator

C++ vs. C#, 105

decrement, in a loop, 102105

description, 101102

guidelines, 105

lock statement, 105106

postfix increment operator, 104105

post-increment operator, 103

prefix increment operator, 104105

pre-increment operator, 103104

race conditions, 105106

thread safety, 105106

/ (forward slash) division operator

description, 9192

overloading, 397399

precedence, 92

. (dot) dot operator, 126, 871

== (equal signs) equality operator

overloading, 396397

in place of = (equal sign) assignment operator, 119120

/ (forward slash) in XML, 25

++ (plus signs) increment operator

C++ vs. C#, 105

decrement, in a loop, 102105

description, 101102

guidelines, 105

lock statement, 105106

postfix increment operator, 104105

post-increment operator, 103

prefix increment operator, 104105

pre-increment operator, 103104

race conditions, 105106

thread safety, 105106

!= (exclamation point, equal sign) inequality operator

overloading, 362, 396397

testing for inequality, 119120

< (less than sign) less than operator, 120, 396397

<= (less than, equal sign) less than or equal operator, 120, 396397

! (exclamation point) logical NOT operator, 122

% (percent sign) modulo, 9192, 397399

* (asterisk) multiplication operator, 9192, 397399

? (question mark) nullable modifier, 6465, 459

?? (question marks) null-coalescing operator, 124125, 126

?. (question mark, dot) null-conditional operator, 125128

| (vertical bar) OR operator, 131, 132, 397399

|| (vertical bars) OR operator, 121

<<= (less than signs, equal) shift left assignment operator, 130

<< (less than signs) shift left operator, 130, 397399

^ (caret) XOR operator, 122, 131, 397399

\ (single backslash character), escape sequence, 46

> (greater than sign), greater than operator, 120, 396397

>= (greater than, equal sign), greater than or equal operator, 120, 396397

=> (equal sign, greater than) lambda operator, 517, 524

>> (greater than signs), shift right operator, 130, 397399

>>= (greater than signs, equal ) shift right assignment operator, 130

~ (tilde) bitwise complement operator, 134

A

Abort() method, 745746

Aborting threads, 745746

Abstract classes. See also Derivation.

defining, 314331

definition, 314

derived from System.Object, 320321

vs. interfaces, 338

polymorphism, 318320

Abstract members

defining, 315317

definition, 314

“is a” relationships, 317

overriding, 317

virtual, 317

Access modifiers. See also Encapsulation.

definition, 233235

on getters and setters, 251252

purpose of, 236

Action delegates, 524525

Activation frame, 182183

Add() method

appending items to lists, 648

inserting dictionary elements, 654655

System.Threading.Interlocked class, 829

thread synchronization, 829830

Addresses. See Pointers and addresses.

Aggregate functions, 618

AggregateException, 557558, 762765

AggregateException.Flatten() method, 780

AggregateException.Handle() method, 764, 780

Aggregation

derivation, 299301

interfaces, 343344

multiple inheritance, interfaces, 343344

Aliasing, namespaces, 179180. See also using directive.

AllocExecutionBlock() method, 857

AllowMultiple member, 707

Alternative flow control statements, 111

Ampersand, equal sign (&=) compound assignment operator, 133134

Ampersand (&) AND operator, 131, 132

Ampersands (&&) AND operator, 121

Angle brackets (< >), in XML, 25

Anonymous functions

definition, 516, 517

guidelines, 533

Anonymous methods. See also Lambda expressions.

definition, 522

guidelines, 523

internals, 527528

parameterless, 523

passing, 522523

Anonymous types

definition, 61, 572

explicit local variables, 263265

generating, 578

implicit local variables, 572576

in query expressions, 625626

type incompatibilities, 576577

type safety, 576577

var keyword, 572576

Antecedent tasks, 757

Apartment-threading models, 846

APIs (application programming interfaces)

calls from P/Invoke, wrappers, 860861

definition, 25

deprecated, 712

as frameworks, 26

Append method, 58

AppendFormat method, 58

Appending items to collections, 648

Applicable method calls, 201

Applications, compiling, 3

Appointment, 291292

__ arglist keyword, 8

ArgumentNullException, 434435, 436

ArgumentOutOfRangeException, 435, 436

Arguments

calling methods, 163, 167168

named, calling methods, 199

Arity (number of type parameters), 471472

Array accessor, 7879

Array declaration

C++ vs. C#, 7274

code example, 7879

Java vs. C#, 7274

Array types, constraint limitations, 484

ArrayList type, 363365

Arrays. See also Collections; Lists; TicTacToe game.

accessing elements of, 73, 7879

of arrays, 78

assigning values to, 7376

binary search, 8183

BinarySearch() method, 8183

Clear() method, 8183

clearing, 8183

common errors, 8687

converting collections to, 646

description, 7172

designating individual items, 71

exceeding the bounds of, 8081

GetLength() method, 8384

indexers, defining, 665666

instantiating, 7476

jagged, 78, 79, 81

length, getting, 8081

Length member, 80

multidimensional, 74, 7779

number of dimensions, 72

number of items, getting, 8081

as operator, 322323

palindromes, 8486

rank, 72, 8384

Reverse() method, 8586

reversing, 8182

reversing strings, 8486

searching, 8183, 651652

size, specifying, 75

sorting, 8182, 8283

strings as, 8486

swapping data elements, 79

three-dimensional, 7778

ToCharArray() method, 8586

two-dimensional, 74, 79. See also TicTacToe game.

type defaults, 73

unsafe covariance, 497498

AsParallel() method, 595

AspNetSynchronizationContext, 794

Assemblies, compiling, 34

Assembly, definition, 34

Assembly attributes, 697698

Assert() method, 97

Association, 225227, 269

Associativity of operators, 92, 9394

Asterisk, equal sign (*=) binary/assignment operator, 399

Asterisk (*) multiplication operator, 9192, 397399

async keyword

purpose of, 786

task-based asynchronous pattern, 781786

Windows UI, 795798

in WinRT, 876

Asynchronous continuations, 756762

Asynchronous delays, 745

Asynchronous high-latency operations with the TPL, 777781

Asynchronous lambdas, 786787

Asynchronous methods, 787791

Asynchronous operations, 736, 741743

Asynchronous tasks. See Multithreading, asynchronous tasks.

AsyncState, 755

At sign (@)

coding verbatim strings, 48

inserting literal backslashes, 49

keyword prefix, 8

Atomic operations, threading problems, 738

Atomicity of reading and writing to variables, 819

AttachedToParent enum, 758

Attributes

adding encryption, 715716

adding metadata about assemblies, 697698

alias command-line options, 701

AllowMultiple member, 707

assembly, 697698

CIL for, 718719

custom, 699700

custom serialization, 714715

decorating properties with, 696697

definition, 683

deserializing objects, 714715

duplicate names, 707

guidelines, 699, 700, 705, 707

initializing with a constructor, 701705

vs. interfaces, 349

named parameters, 707

no-oping a call, 710711

Parse() method, 709

predefined, 709

pseudoattributes, 719

retrieving, 700702

return, 698699

serialization-related, 713714

setting bits or fields in metadata tables. See Pseudoattribute.

uses for, 696

versioning, 716718

warning about deprecated APIs, 712

Automatically implemented properties

description, 240242

initializing, 242

internals, 254

NextId implementation, 273

read-only, 248, 280

Average() method, 618

await keyword

non-Task<T> values, 791792

task-based asynchronous pattern, 781786

Windows UI, 795798

await operator

description, 797798

multithreading with System.Threading.Thread class, 745

in WinRT, 876

B

Backslashes (), as literals, 49

Base classes, inheritance, 302

Base classes, overriding. See also Derivation.

accessing a base member, 312313

base keyword, 313

brittle base class, 307311

constructors, 313314

fragile base class, 307311

introduction, 302

new modifier, 307311

override keyword, 304, 313

sealed modifier, 311312

sealing virtual members, 311312

virtual methods, 302307

virtual modifier, 302307

base keyword, 313

Base members, accessing, 312313

Base type, 220

BCL (Base Class Library), 27, 28, 893, 895

Binary digits, definition, 128

Binary display, string representation of, 132

Binary floating-point types, precision, 97

Binary operators, 397399

Binary search of arrays, 8183

BinaryExpression, 535

BinarySearch() method

bitwise complement of, 652

searching a list, 651652

searching arrays, 8183

BinaryTree<T>, 476477, 670671

Bits, definition, 128

Bitwise complement of BinarySearch() method, 652

Bitwise operators

<< (less than signs), shift left operator, 130

<<= (less than, equal signs), shift left assignment operator, 130

& (ampersand) AND operator, 131, 132, 378

&= (ampersand, equal sign) compound assignment operator, 133134

^= (caret, equal sign) compound assignment operator, 133134

|= (vertical line, equal sign) compound assignment operator, 133134

| (vertical bar) OR operator, 131, 132, 378

^ (caret) XOR operator, 131

>> (greater than signs), shift right operator, 130

>>= (greater than, equal signs), shift right assignment operator, 130

~ (tilde) bitwise complement operator, 134

binary digits, definition, 128

bits, definition, 128

bytes, definition, 128

introduction, 128129

logical operators, 131133

masks, 132

multiplication and division with bit shifting, 130

string representation of a binary display, 132

Block statements. See Code blocks.

BlockingCollection<T>, 840

bool (Boolean) types

description, 45

returning from lambda expres- sions, 520

Boolean expressions. See also Bitwise operators.

< (less than sign), less than operator, 120

<= (less than, equal sign), less than or equal operator, 120

== (equal signs) equality operator, 119120

!= (exclamation point, equal sign) inequality operator, 119120

> (greater than sign), greater than operator, 120

>= (greater than, equal sign), greater than or equal operator, 120

definition, 118119

equality operators, 119120

evaluating. See if statements.

example, 118

relational operators, 119120

Boolean expressions, logical operators

! (exclamation point), logical negation operator, 122

?: (question mark, colon), conditional operator, 123124

?. (question mark, dot), null-conditional operator, 125128

?? (question marks), null-coalescing operator, 124125, 126

&& (ampersands), AND operator, 121

^ (caret), XOR operator, 122

|| (vertical lines), OR operator, 121

. (dot) dot operator, 126

introduction, 120

Boolean values, replacing with enums, 372

Boxing

avoiding during method calls, 369370

code examples, 363364

introduction, 362363

InvalidCastException, 366

performance, 365

synchronizing code, 366368

unboxing, 363364, 366

value types in the lock statement, 366368

Break() method, 808

break statement, 110, 146147

Breaking parallel loop iterations, 808

Brittle base class, 307311

BubbleSort() method, 506510

byte type, 36

Bytes, definition, 128

C

C language

pointer declaration, vs. C#, 865

similarities to C#, 2

C# language

case sensitivity, 2

compiler, 3

definition, 895

C++ language, similarities to C#, 2

C++ language vs. C#

= (assignment operator) vs. == (equality operator), 118

array declaration, 72

delete operator, 224

deterministic destruction, 427, 884

explicit deterministic resource cleanup, 224

garbage collection, 884

global methods, 171

global variables and functions, 266

header files, 174

implicit deterministic resource cleanup, 224

implicit nondeterministic resource cleanup, 224

implicit overriding, 304

increment/decrement operators, 105

local variable scope, 118

main() method, 10

method calls during construction, 307

multiple inheritance, 299

operator order of precedence, 105

operator-only statements, 91

order of operations, 94

partial methods, 174

pointer declaration, 865

preprocessing, 152

pure virtual functions, 317

string concatenation at compile time, 50

switch statement fall-through, 145

var keyword, 575

Variant, 575

void*, 575

void type, 59

Caching data in class collections, 600

Calculate() method, 753

Call site, 182183

Call stack, 182183

Caller, 163

Calling

constructors, 255256, 261262

methods. See Methods, calling.

object initializers, 257259

CamelCase, 7

Cancel() method, 770771

Canceling

parallel loop iterations, 805806

PLINQ queries, 811813

tasks. See Multithreading, canceling tasks.

CancellationToken, 769772

CancellationTokenSource, 770

CancellationTokenSource.Cancel() method, 770771

Capacity() method, 647

Captured variables, 528530

Capturing loop variables, 531533

Caret, equal sign (^=) compound assignment operator, 133134

Caret (^) XOR operator, 122, 131, 397399

Cartesian products, 608, 638639

Casing

formats for identifiers, 67

local variables, 15

Cast operator

defining, 295296

definition, 6566

overloading, 402

Casting

between arrays of enums, 375

between base and derived types, 293294

definition, 65

explicit cast, 65, 294

implicit base type casting, 293294

with inheritance chains, 294295

inside generic methods, 490491

type conversion without, 6970

Catch blocks

catching different exception types, 436437

description, 205206

empty, 442443

general, 440442

with no type, 211212

Catch clause, 762

Catch() method, 439

Catching exceptions

catch blocks, 436437

code sample, 204205

conditional clauses, 438

definition, 204209

description, 436

different exception types, 436437

empty catch blocks, 442443

exception conditions, 438

general catch blocks, 440442

rethrowing existing exceptions, 438439

switch statements, 436

when clauses, 438

Central processing unit (CPU), definition, 734

Chaining

constructors, 261262

inheritance, 292293

multicast delegates, 555

tasks, 757

Changing strings, 5657

char (character) types, 14, 45

Checked block example, 67

Checked conversions, 6668

Checking for null

guidelines, 549

multicast delegates, 548549

Child type, 220

Church, Alonzo, 523524

CIL (Common Intermediate Language). See also CLI (Common Language Infrastructure).

compiling C# source code into, 26, 891892

compiling into machine code, 878

custom attributes, 894895

definition, 895

disassembling, tools for, 33. See also ILDASM.

managed execution, 2628

metadata, 894895

reflection, 894895

sample output, 3133

source languages, 3133

CIL disassembler. See ILDASM.

Class collections. See also IEnumerable interface; IEnumerable<T> interface.

cleaning up after iteration, 586587

error handling, 587

iterating over using while(), 584

resource cleanup, 587

sharing state, 585

sorting, 601603

Class collections, foreach loops

with arrays, 385

code example, 586

with IEnumerable interface, 587

with IEnumerable<T> interface, 583585

modifying collections during, 587588

Class collections, sorting. See also Standard query operators, sorting.

ascending order ThenBy(), 601603

ascending order with OrderBy(), 601603

descending order with OrderByDescending(), 602

descending order with ThenByDescending(), 602

Class definition

definition, 8

guidelines, 8

naming conventions, 8

syntax, 89

class keyword, 478479

Class libraries

definition, 404

referencing, 404405

Class members, definition, 224

Class type

combining with class or struct, 482

constraints, 477478

class vs. struct, 677

Classes

abstract. See Abstract classes.

adding instance methods, 276

association, 225227, 269

association with methods, 163

base. See Base classes.

within classes. See Nested, classes.

declaring, 221224

definition, 222223

derived. See Derivation.

fields, 225

guidelines, 222

identifying support for generics, 692693

inextensible, 273275

instance fields, 225227

instance methods, 227228

instantiating, 221224

vs. interfaces, 347348

member variables, 225

nested, 281283

partial, 284285

polymorphism, 221

private members, 236

refactoring, 290291

sealed, 301302

spanning multiple files, Java vs. C#, 4. See also Partial methods.

splitting across multiple files. See Partial methods.

static, 273275

Clear() method, 8183, 154

Clearing arrays, 8183

CLI (Common Language Infrastructure). See also CIL (Common Intermediate Language); VES (Virtual Execution System).

application domains, 888

assemblies, 888891

compilers, 879882

contents of, 879

CTS (Common Type System), 892

definition, 878, 895

description, 878879

implementations, 879

managed execution, 2627

manifests, 888891

modules, 888891

objects, 892

values, 892

xcopy deployment, 891

Closed over variables, 528530

Closures, 531

CLR (Common Language Runtime), 896. See also Runtime.

CLS (Common Language Specification)

BCL (Base Class Library), 893

definition, 896

description, 893

FCL (Framework Class Library), 893

managed execution, 27

CLU language, 667668

Code access security, 27

Code blocks, 114116

Code readability

vs. brevity, 169

indenting with whitespace, 1213

Coding the observer pattern with multicast delegates

checking for null, 548549

connecting publisher with subscribers, 546547

defining subscriber methods, 544545

defining the publisher, 545546

delegate operators, 550552. See also specific operators.

getting a list of subscribers, 557558

guidelines, checking for null, 549

invoking a delegate, 547

method returns, 558

multicast delegate internals, 554

new delegate instances, 550

passing by reference, 558

removing delegates from a chain, 550552

sequential invocation, 552, 554

thread safe delegate invocation, 550

Cold tasks, 752

Collect() method, 419

Collection classes

dictionary collections, 653657

linked list collections, 663

list collections, 646649

queue collections, 662

sorted collections, 660661

sorting lists, 649650

stack collections, 661662

Collection initializers

definition, 578

description, 258259

initializing anonymous type arrays, 579582

initializing collections, 579

Collection interfaces, customizing

appending items to, 648

comparing dictionary keys, 658659

converting to arrays, 646

counting collection elements, 646

dictionary class vs. list, 644646

finding even elements, 653

finding multiple items, 652653

generic hierarchy, 645

inserting new elements, 651652

lists vs. dictionaries, 644645

order of elements, 657

removing elements, 649

search element not found, 651652

searching arrays, 651652

searching collections, 651653

specifying an indexer, 644646

Collection interfaces with standard query operators

caching data, 600

counting elements with Count(), 595596

deferred execution, 597598, 600601

definition, 588

filtering with Where(), 591592, 597598

guidelines, 596

projecting with Select(), 592594

queryable extensions, 619

race conditions, 595

running LINQ queries in parallel, 594595

sample classes, 588591

sequence diagram, 599

table of, 618

Collections. See also Anonymous types; Arrays; Class collections; Lists.

discarding duplicate members, 639640

filtering, 622

projecting, 622

returning distinct members, 639640

Collections, customizing

accessing elements without modifying the stack, 661662

appending items to, 648

counting elements of, 646

empty, 666667

FIFO (first in, first out), 662

finding even elements, 653

finding multiple items, 652653

indexers, defining, 665666

inserting new elements, 651652, 661662

LIFO (last in, first out), 661

order of elements, 657

removing elements, 649

requirements for equality comparisons, 659660

search element not found, 651652

searching, 651653

Collections, sorting. See also Standard query operators, sorting.

by file size, 633634

by key, 660661

with query expressions, 632633

by value, 660661

COM threading model, controlling, 846

Combine() method

combining delegates, 552

constraint limitations, 484

event internals, 568

vs. Swap() method, 186

CommandLine, 281285

CommandLineAliasAttribute, 701702

CommandLineInfo, 687691, 696

CommandLineSwitchRequiredAttribute, 699701

Comments

vs. clear code, 24

delimited, 24

guidelines, 24

multi-line, 154

preprocessor directives as, 154

single-line, 24

types of, 24

XML delimited, 24

XML single-line, 24

Common Intermediate Language (CIL). See CIL (Common Intermediate Language).

Common Language Infrastructure (CLI). See CLI (Common Language Infrastructure).

The Common Language Infrastructure Annotated Standard, 26

Common Language Runtime. See Runtime.

Common Language Runtime (CLR), 896. See also Runtime.

Common Language Specification (CLS). See CLS (Common Language Specification).

Common Type System (CTS), 27, 892, 896

Compare() method, 45, 505

CompareExchange() method, 828829

CompareExchange<T> method, 829

CompareTo() method, 477, 649650

Comparing

dictionary keys, 658659

for equality, float type, 97100

Comparison operators, 396397

ComparisonHandler delegate, 509, 510512, 514515

Compatible method calls, 201

Compile() method, 535

Compilers

C# language, 3

CLI (Common Language Infrastructure), 879882

CoreCLR compiler, 880

csc.exe compiler, 3

DotGNU Portable NET compiler, 880

JIT (just-in-tme) compiler, 881

mcs.exe compiler, 3

Microsoft Silverlight compiler, 880

Mono, 3

Mono compiler, 3, 880

.NET Compact Framework, 880

.NET Micro Framework, 880

Shared Source CLI, 880

Windows Desktop CLR, 880

Compiling

applications, 3

assemblies, 34

C# source code into CIL, 891892

into CIL, 26

jitting, 881

just-in-time, 26, 881

with the Mono compiler, 3

NGEN tool, 881

Complex memory models, threading problems, 739

Composite formatting, 21

Compress() method, 326327

Concat() method, 618

Concatenating strings, 95

Concrete classes, 314, 317

Concurrent collection classes, 840841

Concurrent operations, definition, 736

ConcurrentBag<T>, 840

ConcurrentDictionary<T>, 840

ConcurrentQueue<T>, 840

ConcurrentStack<T>, 840

Conditional

clauses, catching exceptions, 438

expressions, guidelines, 124

logical operators, overloading, 400

Conditions, 111

ConnectionState, 372

Consequence statements, 111

Console executables, 404

Console input, 1819

Console output

commenting code, 2224

comments, types of, 24

composite formatting, 21

format items, 21

format strings, 21

formatting with string interpolation, 20

overview, 1922

ConsoleListControl, 327331, 336

const field, encapsulation, 277278

const keyword, 106107

Constant expressions, 106107

Constant locals, 106107

Constants

declaring, 107

definition, 106

guidelines, 106

vs. variables, guidelines, 106

Constraints on type parameters. See also Contravariance; Covariance.

class type constraints, 477478

constructor constraints, 480

generic methods, 481482

inheritance, 480482

interface type constraints, 476477

introduction, 473476

multiple constraints, 479

non-nullable value types, 478479

reference types, 478479

Constraints on type parameters, limitations

array types, 484

combining class type with class, 482

combining class type with struct, 482

on constructors, 484486

delegate types, 484

enumerated types, 484

operator constraints, 482483

OR criteria, 483

restricting inheritance, 482

sealed types, 484

Construction initializers, 261262

Constructor constraints, 480

Constructors

calling, 255256

calling one from another, 261262

centralizing initialization, 262263

chaining, 261262

collection initializers, 258259

constraints, 484486

declaring, 255256

default, 256257

definition, 255

exception propagation from, 428

finalizers, 259

in generic types, declaring, 468469

guidelines, 261

introduction, 254

new operator, 256

object initializers, 257259

overloading, 259261

overriding base classes, 313314

static, 271272

Contains() method, 651652, 661662

ContainsValue() method, 656

Context switch, definition, 736

Context switching, 737

Contextual keywords, 6, 679680

Continuation clauses, query expressions, 637638

Continuation tasks, 757

continue statement

description, 148150

guidelines, 144

syntax, 109

ContinueWith() method, 756758, 760761, 764765, 779

Contracts vs. inheritance, 340341

Contravariance

definition, 495

delegates, 526527

enabling with in modifier, 495497

Control flow. See also Flow control.

guidelines, 139

misconceptions, 784

task continuation, 755

within tasks, 784786

Conversion operators, overloading, 401, 403

Converting

collections to arrays, 646

enums to and from strings, 375377

between interfaces and implementing types, 338

types. See Types, conversions between.

Cooler objects, 544546

Cooperative cancellation, definition, 769

Copy() method, 269271, 275277

CopyTo() method, 646

CoreCLR compiler, 880

Count() method, 595596, 618

Count property, 596, 646

CountdownEvent, 839840

Counting

class collection elements with Count(), 595596

collection elements, 646

lines within a file, example, 192193, 194197

CountLines() method, 163

Covariance

definition, 491

delegates, 526527

enabling with out modifier, 492494

guidelines, 498

introduction, 491492

preventing, 492

type safety, 498

unsafe covariance in arrays, 497498

Covariant conversion

definition, 491

restrictions, 494

.cpp file, C++ vs. C#, 174

CPU (central processing unit), definition, 734

Create() factory method, 723724

Create() method, 471472

.cs file extension, 3

csc.exe compiler, 3

CTS (Common Type System), 27, 892, 896

Curly braces ({ })

formatting code, 13

forming code blocks, 114116

in methods, 9, 1011

omitting, 116

as string literals, 54

CurrentTemperature property, 546547

Custom asynchronous methods, 787791

Custom dynamic objects, 726728

Custom serialization attributes, 714715

Customizing

collection interfaces. See Collection interfaces, customizing.

collections. See Collections, customizing.

events, 568569

IEnumerable interface. See Iterators.

IEnumerable<T> interface. See Iterators.

IEnumerator<T> interface. See Iterators.

Customizing, exceptions

defining, 446448

guidelines, 448

serializable exceptions, 449

D

Data

on interfaces, 327

retrieval from files, 233235

Data persistence, 232233

Data types. See Types.

DataStorage, 232235

Deadlocks. See also Thread synchronization.

avoiding, 831832

causes of, 832

non-reentrant locks, 832

prerequisites for, 832

threading problems, 740

Deallocating memory, finalizers, 423

Debugging with preprocessor directives, 154

decimal type, 3839

Declaration spaces, 116118

Declaring

arrays, 7274, 7879

classes, 221224

constants, 107

constructors, 255256

delegate types, 510

events, 560562

finalizers, 422

generic classes, 464

generic delegate types, events, 562

instance fields, 225226

local variables, 1314

methods. See Methods, declaring.

properties, 238240

Decrement() method, 829830

Default constructors, 256257

Default keyword, 73

default operator, 360361

Default types, 4042

Default(bool) keyword, 73

DefaultIfEmpty(), 613614

Default(int) keyword, 73

Deferred execution

implementing, 630631

query expressions, 627630

standard query operators, 597598, 600601

#define preprocessor directive, 153, 155

Delay() method, 745, 845846

Delaying code execution. See Thread synchronization, timers.

delegate keyword, 510, 554

Delegate operators, 550552. See also specific operators.

Delegate types, 484, 508510

Delegates

-= (minus sign, equal sign), delegate operator, 550

BubbleSort() example, 506510

contravariance, 526527

covariance, 526527

creating with a statement lambda, 517518

deferred execution, 630631

definition, 506

executing unsafe code, 872873

vs. expression trees, 536537

general purpose, 524525

guidelines, 525

immutability, 513

instantiating, 510512

internals, 513516

invocation sequence diagram, 553

mapping to function pointers, 861862

method group conversion, 512

method names as arguments, 511512

multicast, 543, 547. See also Coding the observer pattern with multicast delegates.

nesting, 510

with the null-conditional operator, 128

passing with expression lambdas, 520

structural equality, 526527

synchronous, 751

System.Action, 524525

System.Func, 524525

vs. tasks, 751

thread safety, 550

delete operator, C++ vs. C#, 224

Delimited comments, 24

DenyChildAttach enum, 758

Deprecated APIs, 712

Dequeue() method, 662

Dereferencing pointers, 869871

Derivation

abstract classes. See Abstract classes.

aggregation, 299301

casting between base and derived types, 293294

casting with inheritance chains, 294295

classes derived from System.Object, 320321

data conversion with the as operator, 322323

defining custom conversions, 295296

determining the underlying type, 321322

explicit cast, 294

extension methods, 299

implicit base type casting, 293294

implicit conversion, 294

inheritance chains, 292293

“is a” relationships, 293294

is operator, 321322

multiple inheritance, simulating, 299301

overriding base classes. See Base classes, overriding.

private access modifier, 296297

protected access modifier, 297298

refactoring a class, 290291

sealed classes, 301302

single inheritance, 299301

Derived types, 220221

Deserialize() method, 714

Deserializing

documents, 716718

objects, 714715

Deterministic finalization with the using statement, 423426

Diagramming multiple inheritance, 345

Dictionaries, 664666

Dictionary classes

customized collection sorting, 649651

definition, 653

diagrams, 654

hash tables, 656

inserting elements, 654

vs. list, 644646

list collections, 647649

vs. lists, 644646

removing elements, 656

Dictionary collection classes, 644646

Dictionary collections, 653657

Dictionary keys, comparing, 658659

Directives. See Preprocessor directives.

DirectoryCountLines() method, 193199

Directory.GetFiles() method, 625, 632

DirectoryInfoExtension.Copy() method, 269271, 275277

DirectoryInfo.GetFiles() method, 275, 607

Disassembling CIL, tools for, 33. See also ILDASM.

Discarding duplicate collection members, 639640

DispatcherSynchronizationContext, 794

Disposable tasks, 774

Dispose() method, 424425, 426427

Distinct() method, 618, 639641

Dividing by zero, 99100

Division with bit shifting, 130

.dll file extension, 4

DLL (Dynamic Load Library) file extension, 4

do while loops, 108, 134137

Documents

deserializing, 716718

serializing, 716718

versioning, 716718

XML, 416418

Dollar sign, at sign ($@), string interpolation, 50

Dollar sign ($), string interpolation, 48

Dot (.) dot operator, 126, 871

DotGNU Portable NET compiler, 880

Double quotes (“ “), coding string literals, 48

double type, precision, 97

Double.TryParse() method, 215

Dropping namespaces. See using directive.

Dump() method, 337

Duplicate names for attributes, 707

dynamic as System.Object, 723724

Dynamic binding, 724725

dynamic directive, 721

Dynamic Load Library (DLL) file extension, 4

Dynamic member invocation, 722

dynamic principles and behaviors, 721723

dynamic type. See Programming with dynamic objects.

E

#elif preprocessor directive, 153, 154

Eliminating namespaces. See using directive.

Ellipsis (...) binary/assignment operator, 399

Else clauses, 111

#else preprocessor directive, 153, 154

E-mail domain, determining, 149

Empty catch blocks, 442443

Empty<T> method, 667

Encapsulation. See also Access modifiers.

const field, 277278

definition, 224

description, 223224

information hiding, 235237

introduction, 219

public constants, permanent values, 278281

read-only fields, 279281

readonly modifier, 279281

of types, 407408

Encryption for documents, 715716

#endif preprocessor directive, 154

#endregion preprocessor directive, 158159

Enqueue() method, 662

Enter() method, 366, 821, 823, 825826

EntityBase, 477478

EntityBase<T>, 481482

EntityDictionary, 479, 500501

EntityDictionary<T>, 477478

EntityDictionary<TKey, TValue>, 480

Enumerated types, constraint limitations, 484

enums

casting between arrays of, 375

characteristics of, 371372

conversion to and from strings, 375377

defining, 372

definition, 371372

as flags, 377381

FlagsAttribute, 380381

joining values, 378

replacing Boolean values, 372

type compatibility, 374375

underlying type, 373

enums, guidelines

creating enums, 374

default type, 373

enum flags, 379

string conversions, 377

Equal sign, greater than (=>) lambda operator, 517, 524

Equal sign (=) assignment operator

vs. == (equality operator), C++ vs. C#, 118

assigning variables, 16

definition, 16

precedence, 92

Equal signs (==) equality operator

overloading, 396397

in place of = (equal sign) assignment operator, 119120

Equality operators, 119120

Equals() equality operator

implementing, 392395

overloading, 388395

overriding, 392395

requirements for equality comparisons, 659660

Equals() method, overloading, 362

Error handling. See also Exception handling.

APIs, 855857

class collections, 587

multicast delegates, 554556

P/Invoke, 855857

Error messages, disabling/restoring, 156157

#error preprocessor directive, 153, 155156

Errors. See also Exception handling.

emitting with directives, 155156

infinite recursion error, 194

reporting. See Exception handling.

Escape sequences

\ (single backslash character), 46

displaying a smiley face, 4748

list of, 47

, newline character, 46, 48

, tab character, 46

for Unicode characters, 4648

Even() method, 653

Event keyword, 558, 561

Event notification

with multiple threads, 830

thread-safe, 831

Events. See also Coding the observer pattern.

coding conventions, 562564

customizing, 568569

declaring, 560562

declaring generic delegate types, 562

encapsulating the publication, 560

encapsulating the subscription, 559560

generic delegates, 564566

guidelines, 564, 566

internals, 564566

Exception conditions, 438

Exception handling. See also Errors; specific exceptions.

with AggregateException, parallel loop iterations, 803804

appropriate use of, 214215

basic procedures, 202203

catch blocks, 205206, 211212

catching exceptions, 204209

common exception types, 210. See also specific types.

examples, 202203, 204205

for expected situations, 214215

finally blocks, 207208

general catch blocks, 211212

guidelines, 212, 215, 436, 442446

handling order, 207

Java vs. C#, 440

multiple exception types, 433436

numeric conversion, 215216

Parse() method, 215216

passing null exceptions, 434

program flow, 206

reporting errors. See throw statement; Throwing exceptions.

task-based asynchronous pattern, 779780

throwing exceptions, 203204, 212215. See also throw statements.

trapping errors, 203209

try blocks, 205206

TryParse() method, 215216

unhandled exceptions, 203204

Exception propagation from constructors, resource cleanup, 428

Exceptions, custom. See also Errors.

defining, 446448

guidelines, 448

serializable exceptions, 449

Exchange<T> method, 829

Exclamation point, equal sign (!=) inequality operator

overloading, 362, 396397

testing for inequality, 119120

Exclamation point (!) logical NOT operator, 122

Excluding/including code with preprocessor directives, 154

ExecuteSynchronously enum, 759

Execution time, definition, 27

Exit() method, 366, 823, 825826

Exiting a switch section, guidelines, 144

Explicit cast, 6566

Explicit deterministic resource cleanup, C++ vs. C#, 224

Explicit implementation of interfaces, 334, 336337

Explicit member implementation, 334335

Explicitly declared parameter types, 518

Expression bodied methods, 174

Expression lambdas, 520

Expression trees

BinaryExpression, 535

building LINQ queries, 537538

Compile() method, 535

deferred execution, 630631

definition, 533

vs. delegates, 536537

examining, 538541

lambda expressions as data, 534535

LoopExpression, 535

MethodCallExpression, 535

NewExpression, 535

as object graphs, 535536

ParameterExpression, 535

UnaryExpression, 535

Extensible Markup Language (XML). See XML (Extensible Markup Language).

Extension methods

definition, 276

derivation, 299

inheritance, 299

on interfaces, 341343

introduction, 275277

reflection support for, 723

requirements, 276

extern alias directive, 413

extern methods, 851

External functions

calling with P/Invoke, 858860

declaring with P/Invoke, 850851

F

Factory methods, generic types, 471472

FailFast() method, 435, 436

FCL (Framework Class Library), 893, 896

Fibonacci calculator, 135

Fibonacci numbers/series, 135

Fields

declaring as volatile, 828

getter/setter methods, 237238

guidelines, 242244

identifying owner of, 228229

marking as private, 237238

virtual, properties as, 249250

File extensions, 3. See also specific extensions.

FileInfo collections, projecting, 633634

FileInfo object, 593, 625, 633

Filename matching class name, Java vs. C#, 4

Files

data persistence, 232233

data retrieval, 233235

storage and loading, 232235

FileSettingsProvider, 341

FileStream property, 429

Filtering collections

definition, 622

filtering criteria, 631632

predicates, 631

query expressions, 631632

Finalization

guidelines, 428

resource cleanup, 421427

Finalization queue, resource cleanup, 426

Finalizers

deallocating memory, 423

declaring, 422

description, 259, 421

deterministic finalization with the using statement, 423426

Finally blocks, 207208

FindAll() method, 652653

Finding

even elements in collections, 653

multiple items in collections, 652653

fixed statement, 867868

Fixing (pinning) data, 866868

Flags, enums, 377381

FlagsAttribute, 380381, 708709

Flatten() method, 780

Flattening a sequence of sequences, 638639

flNewProtect, 854

float type, 97100

Floating-point types

binary float, 39

decimal, 3839

double, 3738

for financial calculations. See decimal type.

float, 3738

Flow control. See also Control flow.

definition, 734

introduction, 107

Flow control statements. See also specific statements.

alternative, 111

block statements. See Code blocks.

Boolean expressions, evaluating. See if statement.

break, 110

code blocks, 114116. See also Scope.

combining. See Code blocks.

conditions, 111

consequence, 111

continue, 109

declaration spaces, 116118

definition, 89

do while, 108, 134137

for, 109, 137140

foreach, 109, 140142

goto, 110

if, 108, 111, 114

if/else, examples, 111, 113

indentation, 115

nested if, 112113

scopes, 116118. See also Code blocks.

switch, 110, 142146

true/false evaluation, 111

while, 108, 134135, 136137

For loops

CIL equivalent for, 582583

description, 136140

parallel, 819820

for statements, 109, 137140

foreach loops, class collections

with arrays,

code example, 586

with IEnumerable interface, 587

with IEnumerable<T> interface, 583585

modifying collections during, 587588

ForEach() method, 806

foreach statement, 109, 140142

Formal declaration, methods. See Methods, declaring.

Formal parameter declaration, 171172

Formal parameter list, 172

Format items, 21

Format() method, 51

Format strings, 21

FormatMessage() method, 855

Formatting

numbers as hexadecimal, 43

with string interpolation, 20

strings, 54

Forward slash (/) division operator

description, 9192

overloading, 397399

precedence, 92

Forward slash (/) in XML, 25

Fragile base class, 307311

Framework Class Library (FCL), 893, 896

Frameworks, definition, 26

from clause, 623624, 638639

FromCurrentSynchronizationContext() method, 793

Full outer join, definition, 604

Func delegates, 524525

Function pointers, mapping to delegates, 861862

Functions

global, C++ vs. C#, 266

pure virtual, 317

G

Garbage collection

Collect() method, 419

introduction, 418

managed execution, 28

in .NET, 418419

resource cleanup, 426427

root references, 418

strong references, 420421

weak references, 420421

Garbage collector, definition, 223

GC.ReRegisterFinalize() method, 429

General catch blocks, 211212, 440442

General purpose delegates, 524525

Generic classes

declaring, 464

type parameters, 464

undo, with a generic Stack class, 461

Generic delegates, events, 564566

Generic internals

CIL representation, 498500

instantiating based on reference types, 500501

instantiating based on value types, 500501

introduction, 498

Generic methods

casting inside, 490491

constraints, 481482

constraints on type parameters, 481482

guidelines, 491

introduction, 486487

specifying constraints, 489490

type inference, 487489

Generic types

arity (number of type parameters), 471472

benefits of, 464465

constraints. See Constraints on type parameters.

constructors, declaring, 468469

Create() method, 471472

factory methods, 471472

finalizers, declaring, 468469

generic classes, 461

guidelines, 473

implementing, 467

interfaces, description, 466467

interfaces, implementing multiple versions, 467468

introduction, 461462

multiple type parameters, 470471

nesting, 472473

overloading a type definition, 471472

parameterized types, 461

specifying default values, 469470

structs, 466467

Tuple class, 471472

type parameter naming guidelines, 465466

Generic types, generic classes

declaring, 464

type parameters, 464

undo, with a generic Stack class, 461

Generic types, reflection on

classes, identifying support for generics, 692693

determining parameter types, 692

methods, identifying support for generics, 692693

type parameters for generic classes or methods, 693694

typeof operator, 692

Generics, C# without generics

multiple undo operations, 456459

nullable value types, 459461

System.Collection.Stack class, 456459

type safety, 459

using value types, 459

get keyword, 240

GetCurrentProcess() method, 851

GetCustomAttributes() method, 701702

GetDynamicMemberNames() method, 729

GetEnumerator() method, 588, 669

GetFiles() method, 163, 275, 607, 625, 632

GetFirstName() method, 240

GetFullName() method, 170174

GetGenericArguments() method, 693694

GetHashCode() method, 362, 385387, 659660

GetInvocationList() method, 557558

GetLastError API, 855

GetLastName() method, 240

GetLength() method, 8384

GetName() method, 227234

GetProperties() method, 685686

GetResponse() method, 776

GetResponseAsync() method, 779

GetReverseEnumerator() method, 680681

GetSetting() method, 339341

GetSummary() method, 317320

GetSwitches() method, 702704

Getter/setter methods, 237238, 251252

GetType() method, 520, 685686

GetUserInput() method, 170, 172, 182

GetValue() method, 691

GhostDoc tool, 418

Global methods, C++ vs. C#, 171

Global variables and functions, C++ vs. C#, 266

goto statement, 110, 150152

Greater than, equal sign (>=), greater than or equal operator, 120, 396397

Greater than sign (>), greater than operator, 120, 396397

Greater than signs, equal (>>=) shift right assignment operator, 130

Greater than signs (>>), shift right operator, 130, 397399

GreaterThan() method, 512

group by clause, 635637

group clause, 623

GroupBy() method, 610611

Grouping query results, 634637

GroupJoin() method, 611614

Guest computer, definition, 872

H

.h file, C++ vs. C#, 174

Handle() method, 764, 780

Hardcoding values, 4042

Hash tables

balancing, 385387

dictionary classes, 656

Header files, C++ vs. C#, 174

Heaps, 6263

Heater objects, 544546

HelloWorld program

CIL output, 3133

getting started, 23

Hexadecimal numbers

formatting numbers as, 43

notation, 4243

specifying as values, 43

HideScheduler enum, 759

Hill climbing, 802803

Hot tasks, 752

Hungarian notation, 7

Hyper-Threading, definition, 734

Hyphens (-), in identifier names, 7

I

IAngle.MoveTo interface, 367

IAsyncAction<T> interface, 876

ICloseable, 876

ICollection<T> interface, 646

IComparable interface, 649650

IComparable<string>.CompareTo() method, 649650

IComparable<T>, 477, 649650

IComparer<T>, 649651

Id property, 755

Identifiers

camelCase, 7

casing formats, 67

definition, 6

guidelines for, 7

keywords as, 8

naming conventions, 67

PascalCase, 67

syntax, 67

IDictionary<TKey, TValue>, 644646, 653657

IDisposable interface

cleaning up after iterating, 586

resource cleanup, 424425, 426427

Task support for, 774

in WinRT. See ICloseable.

IDisposable.Dispose() method, 424425, 426427

IDistributedSettingsProvider interface, 346

IEnumerable interface

class diagram, 584

CopyTo() method, 646

Count() method, 646

customizing. See Iterators.

foreach loops, class collections, 587

.NET class collections, 582

IEnumerable<T> interface

class diagram, 584

customizing. See Iterators.

foreach loops, 583585

.NET class collections, 582

in WinRT. See IIterable<T>.

IEnumerator<T> interface, customizing. See Iterators.

IEqualityComparer<T> interface, 658659

#if preprocessor directive, 153, 154

if statements, 108, 111, 114, 150

if/else statements, examples, 111, 113

IFileCompression interface, 326327

IFormattable interface, 362, 370, 479, 483485

IIterable<T>, 876

IL. See CIL (Common Intermediate Language).

IL Disassembler. See ILDASM.

ILDASM, 3031

IListable interface, 327335, 342343

IList<T>, 644646

ILMerge.exe utility, 890

Immutability

delegates, 513

strings, 5657

value types, 357

Immutable strings, syntax, 17

Implicit conversion, 65, 6869

Implicit deterministic resource cleanup, C++ vs. C#, 224

Implicit implementation interfaces, 334, 336337

Implicit local variables, anonymous types, 572576

Implicit member implementation, interfaces, 335336

Implicit nondeterministic resource cleanup, C++ vs. C#, 224

Implicit overriding, Java vs. C#, 304

Implicitly typed local variables, 6061

Importing types from namespaces. See using directive.

Imports directive, 176

in modifier, 495497

In type parameter, 526

Increment() method, 829830

Increment/decrement operators (++, --)

C++ vs. C#, 105

decrement, in a loop, 102105

description, 101102

lock statement, 105106

postfix increment operator, 104105

post-increment operator, 103

prefix increment operator, 104105

pre-increment operator, 103104

race conditions, 105106

thread safety, 105106

Indentation, flow control statement, 115

Indexers

defining, 665666

specifying, 644646

IndexOf() method, 651652

Inextensible classes, 273275

Infinite recursion error, 194

Information hiding. See Encapsulation.

Inheritance

base classes, 302

base type, 220

chaining, 292293

child type, 220

constraint limitations, 482

constraints on type parameters, 480482

vs. contracts, 340341

derived types, 220221

extension methods, 299

interfaces, 338341

introduction, 219220

“is a kind of” relationships, 290

multiple, C++ vs. C#, 299

multiple, simulating, 299301

parent type, 220

private members, 296297

purpose of, 290

single, 299301

specializing types, 221

subtypes, 220

super types, 220

value types, 361362

Initialize() method, 244, 263

Initializing attributes with a constructor, 701705

Inner classes, Java, 283

Inner join, 604, 607610

InnerExceptions property, 558, 764, 780, 804

Insert method, 58

Inserting

elements in dictionary classes, 654

new elements in collections, 651652

Instance fields. See also Static, fields.

accessing, 226227

declaring, 225226

definition, 225

Instance methods

adding to a class, 276

definition, 51

introduction, 227228

Instantiating

arrays, 7476

classes, 221224

delegates, 510512

interfaces, 334

Instantiation, 10, 222223

int type, 14, 36, 202203

Integer literals, determining type of, 4142

Integers, type for, 3637

Integral types, 96

Interface type constraints, 476477

Interfaces

vs. abstract classes, 325326, 338

aggregation, 343344

vs. attributes, 349

vs. classes, 347348

contracts vs. inheritance, 340341

converting between interfaces and implementing types, 338

data, 327

defining, 327

deriving one from another, 338341, 346347

extension methods, 341343

inheritance, 338341

instantiating, 334

introduction, 326327

method declarations in, 327

naming conventions, 327

polymorphism, 327332

post-release changes, 346

purpose of, 326327

value types, 361362

versioning, 346347

Interfaces, generic types

description, 466467

finalizers, declaring, 468469

implementing multiple versions, 467468

Interfaces, implementing and using

accessing methods by name, 336

code example, 328332, 332333

explicit implementation, 334, 336337

explicit member implementation, 334335

guidelines, 336337

implicit implementation, 334, 336337

implicit member implementation, 335336

overview, 327

Interfaces, multiple inheritance

aggregation, 343344

diagramming, 345

implementing, 341, 343344

working around single inheritance, 343344

internal access modifiers on type declarations, 407408

internal accessibility modifier, 409

Interpolating strings, 5053

Intersect() method, 618

into keyword, 637

InvalidAddressException, 446

InvalidCastException, 366

Invoke() method, 548549

I/O-bound latency, definition, 732

IObsolete interface, 349

IOrderedEnumerable<T> interface, 602

IProducerConsumerCollection<T>, 840841

IQueryable<T> interface, 619

IReadableSettingsProvider interface, 338341

IReadOnlyPair<T> interface, 492494

“Is a kind of” relationships, 290

“Is a” relationships, 293294, 317

Is operator, verifying underlying types, 321322

IsAlive property, 744

IsBackground property, 743

IsCancellationRequested property, monitoring, 770771

IsCompleted property, 754

ISerializable interface, 449, 715716

ISettingsProvider interface, 339341, 346347

IsInvalid, 858

IsKeyword() method, 628

Items property, 468

Iterating over

class collections using IEnumerable<T>. See IEnumerable<T> interface.

class collections using While(), 584

properties of objects in a collection. See Reflection.

Iterators

canceling iteration, 677678

contextual keywords, 679680

creating a language construct from, 668

defining, 668

functional description, 678679

guidelines, 676

multiple in one class, 680681

nested, 676

origin of, 667668

recursive, 676

reserved keywords, 679680

returning values from, 669671, 673674

state, 671673

struct vs. class, 677

syntax, 668669

yield break statement, 677678

yield return statement, 670671, 673676, 681

ITrace interface, 337

IWriteableSettingsProvider interface, 341

J

Jagged arrays, 78, 79, 81

Java, similarities to C#, 2

Java vs. C#

classes spanning multiple files, 4

exception specifiers, 440

filename matching class name, 4

generics, 500501

implicit overriding, 304

importing namespaces with wildcards, 176

inner classes, 283

main() method, 10

nested classes, 283

partial class, 4

virtual methods by default, 303

JavaScript vs. C#

var keyword, 575

Variant, 575

void*, 575

JIT (just-in-tme) compiler, 881

Jitting, 881. See also Compilers; Compiling; Just-in-time compilation.

Join() method, 607610, 743744

Join operations. See Standard query operators, join operations.

Jump statements

break statement, 146147

continue statement, 148150

goto statement, 150152

if statement, 150

Just-in-time compilation, 26

K

KeyNotFoundException, 656

Keywords. See also specific keywords.

contextual, 6

definition, 4

as identifiers, 8

incompatibilities, 6

list of, 5

placement, 4

reserved, 6, 8

syntax, 46, 8

Kill() method, 789

L

Lambda calculus, 524

Lambda expressions

=> (equal sign, greater than) lambda operator, 517, 524

captured variables, 528530

capturing loop variables, 531533

closed over variables, 528530

closures, 531

as data, 534535

definition, 516

explicitly declared parameter types, 518

expression lambdas, 520

GetType() method, 520

guidelines, 518

internals, 527528

lifetime of captured variables, 530

name origin, 523524

notes and examples, 521522

outer variable CIL implementation, 530531

outer variables, 528530

predicate, definition, 520, 591

returning a bool, 520

sequence of operations, 599

statement lambdas, 517519

typeof() operator, 520

Lambdas, asynchronous, 786787

Language contrast. See specific languages.

Language interoperability, 27

LastIndexOf() method, 651652

Latency

asynchronous high-latency operations with the TPL, 777781

definition, 732

synchronous high-latency operations, 775777

Lazy loading, 429431

LazyCancellation enum, 759

Left outer join, definition, 604

Left-associative operators, 93

Length

arrays, 8081

strings, 5556

Length member, 5556, 80

Less than, equal sign (<=) less than or equal operator, 120, 396397

Less than sign (<) less than operator, 120, 396397

Less than signs, equal (<<=) shift left assignment operator, 130

Less than signs (<<) shift left operator, 130, 397399

let clause, 633634

Libraries

BCL (Base Class Library), 893

class, 404405

definition, 34, 404

FCL (Framework Class Library), 893

file extension, 4

PCLs (portable class libraries), 406

TPL (Task Parallel Library), 733

Library implementation. See CLS (Common Language Specification).

Lifetime of captured variables in lambda expressions, 530

#line preprocessor directive, 153, 157158

Line-based, statements, Visual Basic vs. C#, 11

Linked list collections, 663

LinkedListNode<T>, 663

LinkedList<T>, 663

LINQ queries

building with expression trees, 537538

with query expressions. See Query expressions with LINQ.

running in parallel, 594595

Liskov, Barbara, 667

List collections, 646649

Lists. See also Collections.

vs. dictionaries, 644645

indexers, defining, 665666

sorting, 649650

List<T>

covariance, 492

description, 647649

List<T>.Sort() method, 649650

Literal values

case sensitivity, suffixes, 42

definition, 39

exponential notation, 42

specifying, 3940

strings, 48

Loading

files, 232235

lazy, 429431

Local variable scope, C++ vs. C#, 118

Local variables

assigning values to, 14, 1617

casing, 15

changing values, 1617

declaring, 1314

guidelines for naming, 15

implicitly typed, 6061

naming conventions, 15, 172

unsynchronized, 820

lock keyword, 823825

lock objects, 825

Lock performance, 825

lock statement, 366368, 740

Lock synchronization, 823825

Locking

guidelines, 827

on this, typeof, and string, 826827

threading problems, 740

LockTaken parameter, 823825

Logical operators, 131133. See also Boolean expressions, logical operators.

long type, 36

LongRunning enum, 758

Long-running tasks, 773774

Loop variables, 137, 531533

LoopExpression, 535

Loops

break statement, 110

continue statements, 109

with decrement operator, 102105

do while, 108, 134135

escaping, 146147

for, 109, 137140

foreach, 109, 140142

goto, 110

guidelines, 139

if, 108, 111, 114

if/else, examples, 111, 113

iterations, definition, 136

nested if, 112113

switch, 110

while, 108, 134135, 136137

Loops, jump statements

break, 146147

continue, 148150

goto, 150152

if, 150

lpflOldProtect, 853

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

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