&
bitwise AND, 75–78
logical AND, 69, 70, 72, 73, 237–243, 622–623
pointer operator, 607
&& (short-circuit or conditional AND), 69, 72–73, 237, 239–243
*
multiplication operator, 26, 65
pointer operator, 606–607, 614, 615
@ to designate verbatim string literals, 50–51
@–qualified keywords, 35
|
logical OR, 69, 70, 71–72, 73, 237–243, 622–623
|| (short-circuit or conditional OR), 69, 72, 73, 237, 239–243
[ ], 139, 140, 144, 147, 153, 253, 618
and strings, 161
^
bitwise exclusive OR, 75, 79–80
used with named arguments, 206
:: namespace alias qualifier, 459–463, 636
{ }, 22, 23, 31, 32, 54, 120, 142, 145, 426, 428, 589
used with format specifiers, 45–48
= = (relational operator), 28, 69, 548
and strings, 161, 693, 697–699
=> lambda operator, 425–426
!, 69, 70, 71–72, 237–239, 623
overloading, 234
and strings, 161, 693, 697–699
/** */, 921
///, 921
<
command-line I/O redirection operator, 390–391
relational operator, 28, 69, 232–234, 622
< >, 509
and delegates, 416
– =
compound assignment operator, 74
and delegates, 416–418
->, 609
overloading, 225
%
modulus operator, 65–66
used with custom date and time placeholder characters, 728, 730
and expression lambdas, 426
. (dot operator), 113, 121, 213, 340, 609
+
concatenating strings with, 163, 699
and delegates, 416
used with WriteLine( ), 25
+=
compound assignment operator, 74
and delegates, 416–418
overloading, 225–228
#
used with preprocessor directive, 464
used with WriteLine( ), 47, 723–725
?
conditional operator, 84–85
used with nullable type declaration, 619
?? null coalescing operator, 621–622
>
command-line I/O redirection operator, 390–391
relational operator, 28, 69, 232–234, 622
; (semicolon), 23, 32–33, 94, 145, 421, 568
used in a custom format specifier, 723, 724
~
used in destructor declaration, 133–134
Abort( ), 774–778
abstract type modifier, 302, 309, 313
Access control, 167–174
guidelines for using public and private, 169–170
Access modifiers/specifiers, 112, 118, 167–168, 269–272, 470
Accessors, 253
event, 436–441
using access modifiers with, 268, 269–272, 327, 328
Acos( ), 642
Action delegate, 678–679, 784, 794, 799, 802, 804, 808
Add( ), 654, 820, 821, 822, 832, 845, 846, 857, 860, 863, 864, 865, 870, 893
and collection initializers, 887
AddAfter( ), 854
AddBefore( ), 854
AddFirst( ), 854
AddLast( ), 854
AddMemoryPressure( ), 683, 684
ADO.NET Datasets, 565
AggregateException, 789, 791, 814
using, 798–801
All( ) extension method, 598–599
AllKeys property, 908
AllowMultiple named parameter, 503
AND operator
bitwise (&), 75–78
logical (&), 69, 70, 72, 73, 237–243, 622–623
short-circuit or conditional (&&), 69, 72–73, 237, 239–243
And( ), 841
Any( ) extension method, 598–599
ApplicationException, 362
ArgumentException, 380, 387, 389, 390, 392, 393, 407, 876, 879
ArgumentNullException, 380, 387, 389, 390, 392, 407, 821, 846, 904
ArgumentOutOfRangeException, 380, 827
command-line, 208–210
passing, 176–178
type. See Type argument(s)
variable number of, using, 184–187
Arithmetic operators, 26, 65–69
methods, table of, 664–672
properties, table of, 663
Array.ForEach( ). See ForEach( )
Array(s), 139–154
boundary errors, using indexer to prevent runtime exceptions caused by, 254–257, 260–262
boundary errors, using a property to prevent runtime exceptions caused by, 264–267, 270–272
collection into an, converting a, 830
copying an, 676–677
custom, using indexers and properties to create, 272–276
dynamic, 276, 817, 825, 849, 875
and fixed-size buffers, 616–618
foreach to cycle through, using, 155–158
general forms of, 139–140, 143, 144
and the IEnumerable<T> interface, 566, 567, 570, 586, 596
implemented in C# as objects, 139–140, 150, 189
implicitly typed, 153–154
indexing (accessing elements of), 140–141, 144, 147
initializing, 142, 145–146, 153–154
I/O using, 400–402
Length property of, 150–153, 264–266
multidimensional, 143–148
null-terminated, 613
one-dimensional, 139–143
parameter params, 184–187
of pointers, 615
pointers and, 611–613
predicates and, 677–678
rectangular, 146
reference variables, assigning, 148–149
returned from methods, 189–190
reversing an, 675–676
sorting, 672–675
of strings, 163–164
ArrayList class, 817, 824–830, 843, 849, 873–874, 875
methods, table of commonly used, 825–826
ArrayTypeMismatchException, 361
Arrow operator (–>), 609
ascending contextual keyword, 570, 573, 574
Asin( ), 642
AsOrdered( ) extension method, 814
AsParallel( ) extension method, 812–814, 820
AsQueryable( ) extension method, 820
AsReadOnly<T>( ), 664
alias, 635–636
and DLL files, 492–493
friend, 630
and reflection, 487–493
Assembly class, 488
Assembly property, 476
AsSequential( ), 816
Assignment operator(s)
arithmetic and logical compound (op =), 74
bitwise compound, 83
and operator overloading, 247–248
Assignments
reference variables and, 117–118, 148–149, 336, 337–338
structure, 336–337
type conversion in, 57–60
Atan( ), 642
Atan2( ), 642
Attribute class, 495, 496, 497, 504
Attribute(s), 471, 476, 495–505
attaching, 496–497
built-in, 503–505
conditional, 504
creating, 496
parameters, positional vs. named, 499–503
retrieving, 497–498
Attributes property, 476
AttributeTargets enumeration, 503
AttributeUsage attribute, 496, 503
AuthenticationLevel property, 900
AutoResetEvent class, 769–770, 771
Average( ) extension method, 598–599
Backslash character constants, 49
Barrier class, 774
base keyword
to access a hidden base class member, 286, 291–293
to call a base class constructor, 286–290, 296, 363, 366
BaseAddress property, 917
BaseType property, 476
Big-endian format, 680
BigMul( ), 642
BinaryReader class, 375, 392–398
input methods, table of common, 394
BinarySearch( ), 664, 672, 674, 825, 829, 850
BinaryWriter class, 375, 392, 394–398
output methods, table of common, 393
BindingFlags enumeration, 480
Bit-fields, 732
methods, table of, 841
BitConverter class, 680–681
methods, table of, 680–681
Bitwise operators, 75–83
BlockingCollection<T>, 869–873
and anonymous methods, 421–423
and name hiding, 56
bool value type, 38, 44–45, 647
default value of, 129
and relational operators, 45, 69
Boolean expression, 28
methods, table of, 662
Boxing and unboxing, 315–317
break statement, 87, 91, 93, 104–106, 109, 156
used with yield, 889
BufferedStream class, 373
Buffers, fixed-size, 616–618
byte value type, 38, 39–40, 371, 407, 647
C format specifier, 47–48
C, history of, 3–4
C++, history of, 4
C#
as a component-oriented language, 6–7
case sensitivity of, 23
Internet and, 895
library, 8, 22, 35, 40, 449, 637, 639
and the .NET Framework, 3, 6, 8
as a strongly typed language, 37, 48, 297, 625
version 4.0, new features in, 7
CachePolicy property, 900, 917
Call-by-reference
using ref to create a, 178–180
vs. call-by-value, 176–178
CancelFullGCNotification( ), 683
Cancellation token, 791, 798–801, 814–815
CancellationToken structure, 780, 798, 799, 814, 870
CancellationTokenSource class, 780, 798, 814
CanRead property, 373
CanSeek property, 373
CanTimeout property, 373
CanWrite property, 373
Capacity property, 826–827, 851, 862
Case sensitivity and C#, 23
case statement, 91–94
and goto, 108–109
Cast( ) extension method, 820
Cast(s), 44, 57, 58–60, 62–64, 508, 511, 513, 514
as operator, using the, 472–474
and enumerations, 340–341
and explicit conversion operators, 243, 245–247, 248
and unboxing, 315–316
catch clause, 346–354
for catching all exceptions, 353–354
and catching derived class exceptions, 366–367
and finally, 359
multiple, using, 352–353
and rethrown exceptions, 330
methods, table of, 658–660
char value type, 38, 43–44, 371, 647
Character(s), 43–44
escape sequences, 49
CharacterSet property, 909
checked keyword, 368–370
checksum #pragma option, 469
Class(es), 111–116
abstract, 310–312, 313, 319, 334
base, definition of, 277
constructor. See Constructor(s)
data type, definition creates a new, 113
definition of the term, 8, 12, 22, 111
derived, definition of, 277
generic. See Generic class
library, .NET, 8, 9, 22, 35, 40, 449, 637, 639
member. See Member(s), class
partial, 623–624
scope defined by, 54
sealed, 313
static, 218–220
System, list of, 639–640
well-designed, 112
class keyword, 22, 112, 516, 529, 530, 533
Clear( ), 665, 820, 821, 822, 836, 839, 845, 864, 865
Close( ), 372, 374, 375, 382, 384, 385, 392, 393, 781, 901, 904
CloseMainWindow( ), 781
CLR (Common Language Runtime), 8, 9, 15, 345, 360, 605
CLS (Common Language Specification), 9
Code
bloat, 563
blocks. See Blocks, code
machine, 5
managed vs. unmanaged, 9, 605, 606
point, Unicode character, 657
section, critical, 631
unreachable, 128
unsafe, 605–618
array, conversion into an, 830
initializers, 893
sorting user-defined classes in, 875–881
storing user-defined classes in, 873–875
using an enumerator to access, 882–885
Collection(s), generic, 817, 818, 843–869
interfaces, 844–848
and set operations, 847–848
Collection(s), non-generic, 817–840
classes, 824–840
interfaces, 819–823
CollectionBase class, 843
CollectionCount( ), 683
Collections API, 817, 818, 843
CollectionsUtil class, 843
COM (Component Object Model), 7
interfaces and named arguments, 207
properties, 629–630
Common Language Runtime (CLR), 8, 9, 15, 345, 360, 605
Common Language Specification (CLS), 9
Common Type System (CTS), 9
Compare( ), 159, 160, 161, 162–163, 654, 663, 693, 694–696, 697–699, 823, 847, 879, 880
comparer property, 832
Comparer property, 858, 860, 862, 867, 869
CompareOrdinal( ), 696, 697–699
CompareTo( ), 334, 545, 648, 649, 651, 654, 658, 662, 673, 6409, 693, 696, 823, 875–878
CompareTo(T other), 546, 673, 686, 877–878
Compilation, conditional, 464, 503
Compile( ), 601
Compiler
C# command-line, 14–15
CompleteAdding( ), 871, 872, 873
Components, 6
and C#, 7
and CLS compliance, 9
and the internal access modifier, 470
Concat( ), 699–702
Concat<T>( ), 702
ConcurrentBag<T> collection, 869
ConcurrentDictionary<TKey, TValue> collection, 869
ConcurrentQueue<T> collection, 869, 870
ConcurrentStack<T> collection, 869
Conditional built-in attribute, 503–505
ConnectionGroupName property, 900
Console class, 23, 372, 375, 377, 379, 391
Console.Error, 371, 372, 375, 379
Console.In, 371, 372, 375–379, 390
Console.Out, 371–372, 375, 379, 390
Console.WriteLine( ). See WriteLine( )
ConsoleKey enumeration, 378
ConsoleKeyInfo structure, 378
ConsoleModifiers enumeration, 378
Constants, 37
backslash character, 49
ConstrainedCopy( ), 665
Constraint(s), 515–533
constructor (new ( )), 516, 528–529, 533
and generic interfaces, 544
and generic methods, 539
and generic structures, 536
multiple, using, 533
reference type (class), 516, 529, 530–531, 533
value type (struct), 516, 529, 531
and method overloading, 554
open vs. closed, 511
and static fields, 564
base clause to call a base class, 286–290, 296
in class hierarchy, order of calling, 296–297
and inheritance, 284–290, 296, 299–302
object initializers vs., 201–202, 589
parameterless, 130, 516, 528–529
reflection to obtain a type’s, using, 483–487
structure, 335
ConstructorInfo class, 484
Contains( ), 704–705, 820, 821, 822, 836, 839, 845, 864, 865
extension method, 598–599
ContainsKey( ), 831, 833, 834, 846, 857, 860, 863
ContainsValue( ), 831, 833, 834, 857, 860, 863
ContentEncoding property, 909
ContentLength property, 899, 901, 909
ContentType property, 900, 901, 909
continue statement, 87, 106–107
ContinueWhenAll( ), 796
ContinueWhenAny( ), 796
ContinueWith( ), 794
Control statements. See Statements, control
Conversion operators, 243–247, 251–252
implicit vs. explicit, 243, 245, 247
Conversion, type. See Type conversion
ConvertAll<TInput, TOutput>( ), 665
Cookie class, 910
CookieContainer class, 911
CookieContainer property, 910–911
Cookies, accessing, 910–912
Copy( ), 404–405, 665, 676–677
CopyTo( ), 665–666, 820, 825, 845, 864, 865, 869
Cosh( ), 642
Count property, 820, 827, 841, 844
Count( ) extension method, 584, 598, 600
CountdownEvent class, 774
Covariance, 7, 418–420, 555–558
Create( ) methods defined by Tuple, 685
Create( ) WebRequest method, 899, 903, 904, 907
exceptions, 904
and the Uri class, 907
CreateInstance( ), 666
Credentials property, 900, 917
Cross-language interoperability, 5–6, 469
.cs file extension, 21
csc.exe command-line compiler, 14–15
CTS (Common Type System), 9
CultureInfo class, 160, 657, 694
CultureInfo.CurrentCulture, 160, 657
Current position in a file, 398
Current property, 823, 847, 882, 883, 884, 887
CurrentCulture enumeration value, 697
CurrentCulture StringComparer property, 675, 882
CurrentCultureIgnoreCase enumeration value, 697
CurrentCultureIgnoreCase StringComparer property, 675, 882
CurrentID property, 787–789
CurrentThread property, 779
Data members, class, 111
casting. See Casts
class as a, 113
conversion. See Type conversion
importance of, 37
object as a “universal,” 317–318
promotion of, 61–62
reference. See Reference types
value (simple). See Value types
See also Type
Date and time, formatting, 726–732
custom placeholder characters for, table of, 729
format specifiers for, table of, 726
and objects of type TimeSpan, 730–732
DateTime structure, 405, 686, 726, 728, 730
Decimal .NET structure, 406, 407, 647, 652–657
constructors, 652–653
fields, table of, 657
methods, table of, 654–656
decimal value type, 38, 42–43, 406, 647, 652, 653
literal, 48
DeclaringType property, 475
Decrement operator (– –), 31, 65, 66–67
overloading, 225
Decrement( ), 772–773
default #line directive option, 468
default statement, 91–93
and goto, 108–109
default(type) and type parameters, 534–535
DefaultCachePolicy property, 900
DefaultWebProxy property, 900
#define directive, 463, 464, 503
delegate keyword, 411, 421, 422
Delegate(s), 411–425
and anonymous functions, 420–421, 425
and anonymous methods, 420–425
chains, 416–418
covariance and contravariance and, 418–420
declaring, 411–412
and instance methods, 414–416
and lambda expressions, 425–431
and multicasting, 416–418
reasons to use, 420
System, list of, 641
Delegates, generic, 539–541
and covariance and contravariance, 561–563
Delegates, instantiating, 413
using method group conversion, 414, 415
Dequeue( ), 838, 839, 865, 866
descending contextual keyword, 570, 573
Destructors, 133–135
Dictionaries, 817–818, 822, 857
Dictionary<TKey,TValue> class, 844, 848, 857–859
methods, table of some, 857
Dictionary<TKey,TValue> .KeyCollection class, 858
Dictionary<TKey,TValue> .ValueCollection class, 858
DictionaryBase class, 843
DictionaryEntry structure, 823–824, 832, 834, 884
DirectoryNotFoundException, 381, 390
disable warning option, 469
Dispose( ), 382, 789, 791–792, 799, 847
and the using statement, 633
Divide( ), 654
DivideByZeroException, 345, 350, 351, 355–356, 361
DivRem( ), 642
DLR (Dynamic Language Runtime), 629
Documentation comments, 921–924
do-while loop, 87, 103–104, 107
Dot operator (.), 113, 121, 213, 340, 609
Double .NET structure, 406, 407, 647, 649
fields, table of, 652
methods, table of, 651–652
double value type, 26–27, 38, 40–41, 48, 406, 647
DoubleToInt64Bits( ), 680
DownloadData( ), 918
DownloadFile( ), 918
DownloadString( ), 918
Dynamic Language Runtime (DLR), 629
Dynamic method dispatch, 302
E field, 641
Elapsed property, 808
#elif directive, 463, 464, 466–467
else, 87–90
Encapsulation, 12, 22, 54, 167
Encoding class, 692
Encoding property, 917
#endif directive, 463, 464–465, 466
EndOfStream property, 390
EndOfStreamException, 398
#endregion directive, 463, 468
Enqueue( ), 838, 839, 865, 866
Enter( ), 755
Entry property, 884
Enumerable class, 594, 597, 600, 715, 845
Enumerations, 38, 319, 340–343
formatting, 732–733
and switch statements, 91
System, list of, 641
Enumerators, 817, 818, 822, 882–885
EqualityComparer property, 832
Equals( ), 159, 160, 161, 234, 314, 545, 648, 649, 651, 654, 658, 662, 685, 686, 696, 697–699, 823, 847
Errors
network, handling, 904–907
syntax, 23
See also Exception handling
Escape sequences, character, 49
event statement, 431, 432, 436–437, 440
anonymous methods used as, 441, 442
and event accessors, 436–441
instance methods as, 434–435
lambda expressions used as, 441–442, 445–447
.NET guidelines for 442–445
static methods as, 434, 435–436
Event synchronization object, using an, 769–772
EventArgs class, 442, 444, 445
EventHandler delegate, 444–445
EventHandler<TEventArgs> delegate, 444
multicasting, 433–434
EventWaitHandle class, 769
Exception class, 345, 355, 359–363, 366, 367
Exception handling, 345–370
blocks, general form of, 346, 357
and creating derived exception classes, 356, 362–366
inner, 360
network, 904–907
and uncaught exceptions, 349–351
See also catch clause
See also try block(s)
Exceptions, standard built-in, 345, 360–362
table of common, 361
ExceptionState property, 775, 777
ExceptWith( ), 848
Exit( ), 755
Exp( ), 642
explicit keyword, 243
Expression class, 601
Expression(s)
nullable types in, 620–621
spacing and parentheses in, using, 85
trees, 601–602
type conversion in, 61–64, 620–621
Extension methods, 7, 219, 584, 602–604
and collections, 845
corresponding to query keywords, 594–597
definition of, 594
general form of, 602–603
the inheritance mechanism vs., 602
query-related, 597–601
and String objects, 715
extern
used with methods, 564, 634–635
used to provide an assembly alias, 635–636
Factory property, 792
False displayed as bool value output by WriteLine( ), 45, 662
FalseString field, 662
Field
properties to manage access to, 262–267
readonly, 631–632
unassigned or unused, 618
volatile, 632
File class, 404–406
File Transfer Protocol (FTP), 898
File(s)
DLL, 492–493
I/O. See I/O, file
position indicator (pointer), 398
FileAccess enumeration, 381
FileInfo class, 404
FileMode enumeration, 380
values, table of, 380
FileNotFoundException, 380, 381, 390, 404
FileStream class, 373, 380–387, 391, 392, 393, 398, 404, 405
finally block, 346, 357–359, 383
Find( ), 854
FindLast( ), 854
FindLast<T>( ), 667
FindLastIndex<T>( ), 667
First property, 854
First( ) extension method, 598–599
fixed statement, using the, 608–609, 613–614
and arrays, 611–612
to create fixed-size buffers, 616–618
FixedSize( ), 825
Flags attribute, 732
Flatten( ), 801
float value type, 26, 38, 40, 406, 647
literal, 48
Floating-point(s), 26–28, 40–41
literals, 48
and scientific notation, 48
structures, 649–652
Flush( ), 372, 375, 385, 392, 402
for loop, 29–31, 87, 94–101, 107
and enumerations, 340
parallelized, 801
variations, 96–101
ForAll( ), 816
foreach loop, 87, 104, 154–158, 817, 818, 822
and collections, 882, 884, 885, 887
to execute a query, 566, 568, 570, 583, 600
named iterator to control, using a, 891
ForEach( ) method of the Parallel class, 801, 810–812
Format specifiers for WriteLine( ), 45–48
methods, table of, 719
FormatException, 407
Formatting, 715–733
and cultural settings, 715–716, 726
date and time. See Date and time, formatting
enumerations, 732–733
and format providers, 715–716
and format specifiers, 715–716
using a picture format, 722
Formatting numeric data, 716–725
custom format placeholder characters for, table of, 723
format specifiers for, table of, 717
using String.Format( ), 719–721
using ToString( ), 721–722
using WriteLine( ), 45–48, 715, 716–719
Frank, Ed, 4
nested, 580–581
FromAsync( ), 801
FromOACurrency( ), 654
FTP (File Transfer Protocol) protocol, 898
Func delegate, 796
Func<int, int, bool> delegate type, 602
Func<T,TResult> delegate type, 594
Func<TInner, TKey> delegate type, 595
Func<TOuter, TInner, TResult> delegate type, 595
Func<TOuter, TKey> delegate type, 595
Function
Garbage collection, 133–135, 188, 616, 682–684, 792
and arrays, 139
and fixed, 608
and strings, 165
GC class, 682–684
methods, table of, 683–684
Generic class
example with one type parameter, 508–511
example with two type parameters, 514–515
general form, 515
hierarchies, 548–552
instantiation process for, 563
overriding virtual methods in a, 552–553
partial, 624
reference to a, declaring a, 515
Generic method(s), 536–539, 564
and constraints, 539
and explicit type arguments, 539
general form, 538
avoiding runtime errors through, 513
and code-bloat, 563
restrictions on using, 564
and type safety, 507, 508, 510, 511–514, 518, 538, 539, 541, 564, 663, 673, 686, 818, 844, 874, 875
get accessor
and access modifiers, 269–272
and auto-implemented properties, 267–268, 270
for property, 262, 264, 269, 326–327
get contextual keyword, 34
Get( ), 841
GetBits( ), 654
GetBytes( ), 680
GetCreationTime( ), 406
GetCustomAttribute( ), 497
GetCustomAttributes( ), 476, 497
GetCustomAttributesData( ), 476
GetEnumerator( ), 667, 820, 822, 831, 833, 834, 845, 847, 862, 863, 883, 886–887
GetEvents( ), 476
GetFields( ), 476
GetGeneration( ), 683
GetGenericArguments( ), 476
GetHashCode( ), 234, 314, 545, 648, 649, 651, 654, 658, 662, 685, 686, 823, 847
GetLastAccessTime( ), 404, 405–406
GetLastWriteTime( ), 406
GetLength( ), 667
GetLongLength( ), 667
GetLowerBound( ), 667
GetMembers( ), 476
BindingFlags form of, 480–481, 495
GetNumericValue( ), 658
GetProperties( ), 476
GetRequestStream( ), 899
GetResponse( ), 899, 900, 903, 904
exceptions, 905
GetResponseStream( ), 901, 903, 904, 916
exceptions, 905
GetTotalMemory( ), 683
GetTypeCode( ), 648, 649, 651, 654, 658, 662
GetUnicodeCategory( ), 658
GetUpperBound( ), 667
GetValue( ), 668
GetValues( ), 908
GetViewBetween( ), 868
global predefined identifier, 462–463
group clause, 568, 570–571, 581–583
using into with a, 583–584
GroupBy( ) extension method, 594, 596
Handle( ), 801
Hash table, 831
HashSet<T> class, 849, 866–868
Hashtable class, 817, 824, 831–833, 844, 857
methods, table of common, 831
HasValue property, 619
hcp property, 832
Headers, accessing HTTP, 908–910
Headers property, 900, 901, 908, 909, 917
Heap, 616
Hejlsberg, Anders, 6
Hexadecimal literals, 49
hidden option for #line directive, 468
Hierarchical classification, 13, 277
High surrogate, 657
Host property, 907–908
HTTP (HyperText Transfer Protocol), 897, 898, 901
cookies, accessing, 910–912
header, accessing, 908–910
HttpStatusCode, 897
HttpWebRequest class, 896, 897, 898, 901, 903, 904, 910
HttpWebResponse class, 896, 897, 898, 901, 903, 904, 908–912
properties, table of, 909
HybridDictionary class, 843
ICloneable interface, 663, 686–688, 692, 824, 831, 833, 836, 838, 840
ICollection interface, 334, 663, 819–820, 821, 822, 824, 827, 831, 833, 836, 838, 840, 849, 853, 857, 858, 859, 860, 862, 864, 865, 868, 869, 870, 910
properties, 820
ICollection<KeyValuePair<TKey, TValue>> interface, 846, 857, 859, 862
ICollection<T> interface, 844–845, 847, 849, 853, 864, 865, 866, 868
IComparable interface, 334, 545, 548, 648, 649, 653, 657, 662, 673, 685–686, 692
implementing the, 875–877
IComparable<bool> interface, 662
IComparable<char> interface, 657
IComparable<decimal> interface, 653
IComparable<string> interface, 692
IComparable<T> interface, 545–548, 648, 649, 673, 685–686
implementing the, 877–878
IComparer interface, 663, 674–675, 819, 823, 859, 882
using an 875, 878–880
IComparer<String> interface, 882
IComparer<T> interface, 663, 675, 844, 847
using an, 880–881
IConvertible interface, 648, 649, 653, 657, 662, 686, 692
Id property, 787
Identifiers, 34–35
IDeserializationCallback interface, 653, 831, 853, 857, 866, 868
IDictionary interface, 819, 821–822, 831, 832, 833, 834, 857, 859, 862
methods, table of, 822
IDictionary<TKey,TValue> interface, 844, 846, 857, 858, 859, 862
methods, table of, 846
IDictionaryEnumerator interface, 819, 822, 831, 833, 884–885
IDisposable interface, 633, 791, 870
IEEERemainder( ), 642
IEnumerable interface, 566, 570, 584, 663, 692, 818, 819, 820, 821, 822, 824, 831, 833, 836, 838, 840, 844, 845, 846, 847, 849, 853, 857, 858, 859, 860, 862, 864, 865, 866, 868, 869, 870, 888, 890, 910
implementing the, 885–887
IEnumerable<char> interface, 692
IEnumerable<IGrouping<TKey, TElement>, 581
IEnumerable<KeyValuePair <TKey,TValue>> interface, 846, 857, 859, 862
IEnumerable<T> interface, 566, 567, 569–570, 586, 594, 596, 597, 702, 715, 810, 818, 844, 845, 846, 847, 849, 853, 864, 865, 866, 868, 869, 870, 892
IEnumerator interface, 334, 818, 819, 822–823, 847, 882, 884, 888
implementing the, 885–887
IEnumerator<T> interface, 818, 844, 846, 847, 882, 892, 893
IEqualityComparer interface, 819, 823, 882
IEqualityComparer<String> interface, 882
IEqualityComparer<T> interface, 844, 847
IEquatable<bool> interface, 662
IEquatable<char> interface, 657
IEquatable<decimal> interface, 653
IEquatable<string> interface, 692
IEquatable<T> interface, 545, 548, 648, 649, 686
#if directive, 463, 464–466, 503
if-else-if ladder, 89–90
IFormattable interface, 648, 649, 653, 688
IFormatProvider interface, 647, 688, 716
IGrouping<TKey, TElement>, 581, 583
IHashCodeProvider interface, 819
IList interface, 663, 819, 820–821, 824, 849
methods, table of, 821
IList<T> interface, 844, 845, 848, 849
ImpersonationLevel property, 900
Implication operation, 71–72
implicit keyword, 243
in keyword, 7, 558, 559, 561, 563
Increment operator (++), 30–31, 65, 66–69
overloading, 225–228
Increment( ), 772–773
Indentation style, 33
abstract, 309
and generics, 564
multidimensional, 260–262
one-dimensional, 253–260
overriding, 305
and properties to create a custom array, using, 270–272
read-only or write-only, creating, 257
restrictions, 260
virtual, 305
IndexOf( ), 159, 160, 668, 702, 705–706, 820, 821, 826, 845, 850
IndexOfValue( ), 833, 834, 863
IndexOutOfRangeException, 143, 346–347, 350, 351, 361
Indirection, 606
multiple, 614–615
and abstract classes, 310
basics of, 277–280
and class member access, 280–284
and constructors, 284–290, 296–297, 299–302
and generic classes, 548–552
and interfaces, 330–331
multilevel hierarchy of, 280, 293–296
sealed to prevent, using, 313
structures and, 335
syntax for class declaration that uses, 279, 280
Inherited named parameter, 503
Initialize( ), 669
InnerException property, 360, 798
InnerExceptions property, 798
Insert( ), 713–714, 820, 821, 845
See also Object(s)
Instance variables
and constructors, 129
declaring, 113
definition of, 12
static methods and, 214–215
this to access hidden, using, 137
as unique to their object, 113, 115–116
int value type, 25, 26–27, 38, 39, 40, 406, 647
Int16 .NET structure, 406, 407, 647
Int32 .NET structure, 406, 407, 647
methods supported by, table of, 616–617
Int64 .NET structure, 406, 407, 647
Int64BitsToDouble( ), 680
promotion, 61
Integer structures, 647–648
methods, 648
Interface(s), 319–334
abstract class vs., 334
explicit implementation of, 331–334
general form of, 320
implementing, 320–324
and inheritance, 330–331
.NET Framework standard, 334
partial, 623
reference variables, 324–326
System, list of, 640
Interfaces, generic, 541–544
and contravariance, 558–561
and covariance, 555–558
and inheritance, 557–558
internal access modifier, 167, 168, 470
InternalsVisibleTo attribute, 630
access fundamentals, 898–904
and portability, 5
IntersectWith( ), 848
into
to create a continuation, using, 583–584
to create a group join, using, 589, 591–594
InvalidCastException, 361
InvalidOperationException, 619, 621, 792, 836, 838, 864, 865, 905
InvariantCulture enumeration value, 697
InvariantCulture property, 675, 882
InvariantCultureIgnoreCase enumeration value, 697
InvariantCultureIgnoreCase property, 675 882
Invoke( ), 481–483, 484, 627, 629
defined by the Parallel class, 801, 802–804
I/O, 371–409
array, 400–402
memory-based, 400–404
redirection, 372, 379, 390–392, 402
streams. See Streams
string, 402–404
I/O, file, 380–400
and binary data, 392–398
byte-oriented, 380–386
File class and, 404–406
random access, 398–400
IObservable<T> interface, 689
IObserver<T> interface, 689
IOException, 372, 374, 375, 376, 380, 381, 382, 385, 388, 390, 392, 393, 399, 404, 405, 905
IProducerConsumerCollection <T> interface, 869, 870
IQueryable<T> interface, 594
is operator, 471–472, 473, 474
IsAddingComplete property, 871–872
IsAlive property, 742–743
IsArray property, 476
IsBackground property, 747
IsBusy property, 917
IsCanceled, 799
IsCancellationRequested
property, 798–799
IsCompleted property, 808, 871–873
IsControl( ), 658
IsDefined( ), 476
IsEnum property, 476
ISerializable interface, 831, 853, 857, 866, 868
ISet<T> interface, 844, 847, 866, 867, 868
set operations, table of, 848
IsFixedSize property, 663, 821, 822
IsFromCache property, 901, 909
IsGenericParameter
property, 476
IsGenericType property, 476
IsHighSurrogate( ), 658
IsLetter( ), 659
IsLetterOrDigit( ), 659
IsLittleEndian field, 680
IsLower( ), 659
IsLowSurrogate( ), 659
IsMutuallyAuthenticated
IsNegativeInfinity( ), 650, 651
IsNumber( ), 659
IsPositiveInfinity( ), 650, 651
IsProperSubsetOf( ), 848
IsProperSupersetOf( ), 848
IsPunctuation( ), 659
IsReadOnly property, 663, 821, 822, 844, 864, 865
IsSeparator( ), 659
IsSubsetOf( ), 848
IsSupersetOf( ), 848
IsSurrogate( ), 659
IsSurrogatePair( ), 659
IsSymbol( ), 659
IsSynchronized property, 663, 820, 841
IStructuralComparable interface, 663, 819, 823
IStructuralEquatable interface, 663, 819, 823
IsUpper( ), 659
IsWhiteSpace( ), 660
generic, 892–893
named, 890–892
stopping, 889
Java
features lacking in, 5–6
history of, 4–5
Java Virtual Machine (JVM), 5, 6
join clause, 586–589
using into with a, 589, 591–594
Join( ), 708–709, 711, 743–745, 774, 779, 780
extension method, 594–595, 597
KeepAlive( ), 683
Key, definition of, 821
Key property, 378, 581, 823–824, 848, 858, 861, 884
KeyChar property, 378
KeydByTypeCollection<T> class, 848
Keys property, 822, 832, 833, 834, 846, 858, 860, 862
Keys<TKey> property, 846
KeyValuePair<TKey,TValue> structure, 848, 858, 860–861, 862
Kill( ), 782
Label, 107
Lambda expression(s), 7, 411, 420–421, 425–431
as event handlers, 441–442, 445–447
expression, 426–428
and expression trees, 601–602
and LINQ, 566
and query methods to create queries, 595–597
as a task, using a, 792–794
Last property, 854
Last( ) extension method, 598–599
LastIndexOf( ), 159, 160, 582, 669, 702, 706–707, 826, 850
LastIndexOf<T>( ), 669
LastModified property, 909, 912
Length property
of arrays, 150–153, 264–266, 663
of BitArray, 841
of Stream, 373
let clause, 585–586
Library, .NET Framework class, 8, 9, 22, 35, 40, 314, 449, 637, 639
LinkedList<T> class, 843, 849, 853–857
methods, table of a sampling of, 854–855
LinkedListNode<T> class, 853
LINQ (language-integrated query), 7, 565–604
and ADO.NET Datasets, 565
and extension methods, 219, 566, 602, 820, 845
fundamentals, 566–571
and implicitly typed arrays, 153, 154
and implicitly typed variables, 54, 567, 591
and lambda expressions, 566
and object initializers, 201, 202, 269
and XML files, 565
See also Query
List, doubly linked, 853–857
List property, 853
List<T> class, 843, 849–853, 874–875
methods, table of a sampling of, 850–851
ListDictionary class, 843
Little-endian format, 680
LocalPath property, 907–908
lock, 630–631, 750–755, 756, 759, 760, 762
and SpinLock, 781
Log( ), 642
Log10( ), 643
Logical operators, 69–73
and nullable objects, 622–623
overloading the, 237–243
long value type, 38, 39, 406, 647
literal, 48
LongLength property, 663
Loops
break to exit, using, 104–106
for. See for loop
foreach. See foreach loop
infinite, 100
Low surrogate, 657
LowestBreakIteration
property, 808
M and m suffixes to specify a decimal, 42, 48
Machine code, 5
Main( ), 22, 23, 112, 118, 208–210, 213, 492–493
and command-line arguments, 208–210
and waiting for a task to finish, 786, 789–791, 795
Manifest, assembly, 469
ManualResetEvent class, 769–772
ManualResetEventSlim class, 774
Math class, 40, 41, 195, 641–646
methods, table of, 642–644
Max property, 869
Max( ), 643
extension method, 598–599
MaxGeneration property, 682–683
MaxValue field, 647, 651, 652, 657
access and inheritance, 280–284
controlling access to, 112, 167–174
dot operator to access, 113, 121, 207
static, 213
MemberInfo class, 475–476, 477, 484, 497
MemberType property, 475
MemberTypes enumeration, 475
MemberwiseClone( ), 314, 685, 686, 688
Memory allocation
using stackalloc, 616
Memory management, 682–684
MemoryStream class, 373, 400–402
Message property of Exception, 359–360
Metadata, 9 495
type, 469
MetadataToken property, 475
anonymous, 7, 420–425, 429, 441, 442
base to access hidden, using, 291, 292–293
calling, 121, 481–483, 493–495
conditional, 503–505
and covariance and contravariance, 418–420
delegates and, 411–425
dispatch, dynamic, 302
dot operator (.) and, 113, 121, 213
extension. See Extension methods
extern, 634–635
general form of, 118
generic. See Generic method(s)
and interfaces, 319–320, 321, 331–334
and multicasting, 416–418
overloading, 190–195, 202, 204–205, 553–554
overriding. See Overriding, method
and parameters. See Parameter(s)
partial, 624–625
passing objects (reference types) to, 174–178
private members accessed by public, 167, 169, 170, 173
query. See Query methods
recursive, 210–213
reflection to obtain
information about, using, 477–481
return type of, 123
returning arrays from, 189–190
returning from a void, 121–122
returning objects from, 187–190
returning a value from, 122–124
returning more than one value from, 178, 180–183
scope defined by, 54–56
signature, 195
unreachable code and, 128
virtual, 299, 302–309, 313, 552–553
MethodImplAttribute attribute, 760–762
MethodImplOptions. Synchronized attribute, 760
MethodInfo class, 477, 481, 484
Microsoft Intermediate Language (MSIL), 8–9, 15, 469, 563
Min property, 869
Min( ), 643
extension method, 598–599
MinusOne field, 657
MinValue field, 647, 651, 652, 657
Modifiers property, 378
Module property, 475
Modulus operator (%), 65–66
Monitor class, 755–756
MoveNext( ), 823, 847, 882, 883, 884, 887
MSIL (Microsoft Intermediate Language), 8–9, 15, 469, 563
Multicasting
delegates and, 416–418
and events, 433–434
Multiply( ), 654
Multitasking, 736
process-based, using, 781–782
thread-based vs. processbased, 736
Multithreaded programming, 7, 630–631 735–782
and race conditions, 760
synchronization and. See Synchronization
and the Task Parallel Library (TPL). See Task Parallel Library (TPL)
tips for effective, 781
named, 766
MutexSecurity, 766
Name hiding
and code blocks, 56
Name property, 475, 477, 739, 910
namespace keyword, 450
Namespace property, 476
additive characteristic of, 456–458
alias qualifier (::), 459–463, 636
default global, 449, 459, 462–463
nested, 458–459
qualification, 24, 451, 458, 459
NameValueCollection class, 843
Narrowing conversion, 58–60
Naughton, Patrick, 4
Negate( ), 654
Negative numbers, representation of, 39, 83
NegativeInfinity field, 651, 652
assemblies, 469–470
class library, 8, 9, 22, 35, 40, 314, 449, 637, 639
event guidelines, 442–445
I/O system, 371, 372, 373, 380
standard interfaces, 334
structures for the built-in value types, 406–407, 646–662
.NET Reflection API, 475, 477, 488
Networking, Internet, 895–920
error handling, 904–907
simple example program for, 901–904
web crawler program for, 913–916
new, 116–117, 130, 132–133, 139, 140, 142, 143, 310, 335, 336, 356
to hide base class member, 290–291, 293
to hide interface member, 331
and implicitly typed arrays, 153, 154
used in object initialization syntax, 201–202
new{ } to create an anonymous type, 589, 591
Next( ), 682
NextBytes( ), 682
NextDouble( ), 682
NOT operator
logical unary (!), 69, 70, 71–72, 237–239, 623
Not( ), 841
NotSupportedException, 372, 381, 382, 384, 385, 399, 820, 845, 904, 905
Null
coalescing operator (??), 621–622
reference, 361
null value, 361, 530, 534, 618, 619, 621, 622, 623
Nullable type, 38, 530, 531, 618–623
Nullable<T> class, 618–619
NullReferenceException, 361–362
NumberStyles enumeration, 647
Nybble, 248
Oak, 4
attributes of, obtaining the, 497–498
class factory to construct, using a, 188–189
copies of, deep vs. shallow, 686, 688
to methods, passing, 174–178
observer pattern, 689
reflection for runtime instantiation of, using, 483–487
returning, 187–190
methods defined by, table of, 685
object class, 313–318, 479, 507–508, 512, 513, 818
methods defined by, table of, 314
reference to value type, 315–317
Object initialization
with another object, 197–200
with constructor, 128–132
with object initializer syntax, 201–202, 268–269, 589
Object.Equals( ), 234
Object.HashCode( ), 234
Object-oriented programming (OOP), 4, 11–13, 111, 167, 169, 277
ObjectDisposedException, 382, 384, 385, 789, 905
Observer pattern, 689
Obsolete built-in attribute, 503, 505
OfType( ) extension method, 820 on, 586, 588
OnCompleted( ), 689
One field, 657
OnError( ), 689
One’s complement (unary NOT) operator (~), 75, 80–81
OnNext( ), 689
OpenRead( ), 918
OpenWrite( ), 918
OperationCanceledException, 798, 814
operator keyword, 221
Operator overloading, 221–252, 554
logical, 237–243
and overloading an operator method, 228–232
relational, 232–234
restrictions, 247–248
and true and false, 234–237, 239–243
Operator(s)
? conditional, 84–85
?? null coalescing, 621–622
arrow (–>), 609
assignment. See Assignment operator(s)
bitwise, 75–83
conversion. See Conversion operators
decrement. See Decrement operator (- -)
and generics, 564
implication, 71–72
increment. See Increment operator (++)
lambda (=>), 425–426
logical. See Logical operators
parentheses and, 85
pointer, 607
precedence, table of, 86
relational. See Relational operators
OR operator (|)
logical, 69, 70, 71–72, 73, 237–243, 622–623
OR operator, short-circuit or conditional (||), 69, 72, 73, 237, 239–243
Or( ), 841
orderby clause, 572–576
OrderBy( ) extension method, 594
OrderedDictionary class, 843
Ordinal enumeration value, 697
OrdinalIgnoreCase enumeration value, 697
OrdinalIgnoreCase property, 675, 882
out parameter modifier, 7, 178, 180–183, 194–195, 222, 260, 269, 555, 558, 563
OutOfMemoryException, 361
Overflow in arithmetic computations, 368
and checked and unchecked, 368–370
Overlaps( ), 848
Overloading
methods, 190–195, 202, 204–205, 553–554
operators. See Operator overloading
Overriding, method, 302–312
and dynamic method dispatch, 302
and virtual methods in a generic class, 552–553
PadLeft( ), 711–712
PadRight( ), 711–712
Parallel class, 801–812
Parallel LINQ (PLINQ), 7, 604, 735, 783–784
and the cancellation subsystem, 798
and concurrent collections, 869
efficiency concerns, 816
and queries, 812–816
Parallel programming, 7, 783–784
concurrent collections designed for, 869–873
and data parallelism, 784, 801, 804–812
and task parallelism, 784, 801–804
See also Task(s)
ParallelEnumerable class, 812, 814, 816
ParallelExecutionMode. ForceParallelism, 816
ParallelLoopResult structure, 804
ParallelLoopState class, 808, 811
Parameter(s), 118
and constructors, 130
and methods, 124–128
modifiers, ref and out, 178–184
and named arguments, 206–208, 499
and overloaded methods, 190–195
positional vs. named attribute, 499–503
reference types as, using, 174
type. See Type parameter(s)
variable-length, 184–187
ParameterInfo class, 477
ParameterizedThreadStart delegate, 745–746, 747
ParameterType property, 477
params parameter modifier, 184–187, 195
Parse( ) methods, 406–409, 648, 650, 651, 654–655, 660, 662
partial contextual keyword, 34, 623, 624
PathAndQuery property, 907–908
PathTooLongException, 380–381
Peek( ), 374, 836, 839, 864, 865, 866
Permits, semaphore, 766–767
PI field, 641
PLINQ. See Parallel LINQ (PLINQ)
comparisons, 611
indexing, 612–613
multiple indirection and, 614–615
operators, 607
referent type of, 606, 610, 611
and strings, 613–614
and structures, 609
Polymorphism, 12–13
and overridden methods, runtime, 302, 305
and interfaces, 319
and overloaded methods, 190, 195
Port property, 907–908
PositiveInfinity field, 651, 652
PreAuthenticate property, 900
Predicate delegate, 677–678
Preprocessor directives, 463–469
Primitive types, 37
Priority property, 748
private access specifier, 167–169
Private class members and inheritance, 280–283, 284
Projection initializer, 591
Process class, 781
Process, definition of, 735
Producer/consumer pattern, 869, 870
Programming
multithreaded. See Multithreaded programming
object-oriented (OOP), 4, 11–13, 111, 167, 169, 277
parallel. See Parallel programming
Properties, 12, 253, 262–276, 284
access private base class members using, 281–283, 284
abstract, 309
auto-implemented, 7, 263, 267–268, 270–272, 327
and generics, 564
indexed COM, 629–630
and indexers to create a custom array, using, 272–276
and object initializers, 268–269
overridden, 305
read-only or write-only, creating, 264
restrictions on, 269
virtual, 305
protected access specifier, 167, 281, 283–284, 470
Protocol, network, 897
ProtocolVersion property, 909
ProtocolViolationException, 905
public access specifier, 112, 118, 167–169
and inheritance, 284
Pulse( ), 756–759
PulseAll( ), 756
Queue class, 817, 824, 838–840
methods, table of, 839
methods, table of, 866
Query
and anonymous types, 589–591
contextual keywords, list of, 570
continuation, 583–584
data types, relationship among, 569–570
definition of a, 566
determining what is obtained by a, 568, 570, 576–579
general form of a, 570–571
group results of a, 581–583
joining two data sources in a, 586–589
parallel, 812–816
property, 907–908
range variable, 567, 569–570, 576
sort results of a, 572–576
values returned by a, filter, 568, 571–572
variable in a, create a, 585–586
Query, creating a, 566
using the query methods, 594–597
using the query syntax, 567–568, 597
Query execution, 566, 568–569, 570
deferred vs. immediate, 600–601
Query methods, 594–599
corresponding to the query keywords, 594–595
and lambda expressions to create queries, using, 595–597
QueryString property, 917
Quicksort algorithm, 213
Race condition, 760
Random access file I/O, 398–400
Random class, 681–682
methods, table of, 682
Random numbers, generating, 681–682
Rank property, 663
Read( ), 372, 374, 375–376, 379, 382, 393
ReadBlock( ), 374
ReadByte( ), 372, 382–384, 394, 904
ReadLine( ), 374, 375, 376–377, 379, 390, 402, 404
readonly, 631–632
ReadOnly( ), 826
ReadOnlyCollectionBase class, 843
ReadTimeout property, 373
Recursion, 210–213
ref parameter modifier, 178–180, 183–184, 194–195, 222, 260, 269
to methods, passing, 174–178
using ref and out with, 183–184
Reference variable(s)
derived class objects and base class, 297–302, 309
and assignment, 117–118, 148–149
declaring, 116–117
interface, 324–326
ReflectedType property, 475
and assemblies, 487–493
to call methods, using, 481–483
dynamic type with, using the, 627–629
and fully automated type discovery, 493–495
to obtain a type’s constructors, 483–487
RegisterForFullGCNotification( ), 683
RegisterPrefix( ), 898
Relational operators, 28, 45, 69–70
and nullable objects, 622
overloading, 234–236
Release( ), 767
Remainder operator (%), 65–66
Remainder( ), 655
remove event accessor, 437, 440
Remove( ), 713–714, 820, 821, 822, 845, 846, 855, 857, 860, 863, 864, 865
RemoveAt( ), 820, 821, 845, 863
RemoveFirst( ), 855
RemoveLast( ), 855
RemoveMemoryPressure( ), 683, 684
RequestUri property, 901
ReRegisterForFinalize( ), 683
Reset( ), 770, 772, 808, 823, 847, 882–883, 887
ResetAbort( ), 777–778
Resize<T>( ), 669
Response property, 905
ResponseHeaders property, 917
ResponseUri property, 901, 909
restore warning option, 469
Result property, 796
return statement, 87, 107, 121–122, 178, 422, 423, 429
used with yield, 888
ReturnType property, 477
Reverse( ), 669–670, 675–676, 825, 826, 850, 868
Ritchie, Dennis, 3
Runtime type identification (RTTI), 471–475
Sample( ), 682
SByte .NET structure, 407, 647
sbyte value type, 38, 39–40, 407, 647
Scheme property, 907–908
sealed keyword, 313
SecurityException, 380
SeekOrigin enumeration, 399
select clause, 568, 570, 576–579, 581, 589
into with a, using, 583
and projecting, 576
using a projection initializer, 591
Select( ) extension method, 594, 595–596
Selection statements, 87–94
named, 769
SemaphoreSecurity, 769
SemaphoreSlim class, 774
SerializationInfo, 360
Server property, 909
set accessor
and accessor modifiers, 269–272
and auto-implemented properties, 267–268, 270–272
for property, 262–263, 264, 326–327
set contextual keyword, 34
SetAll( ), 841
SetEquals( ), 848
SetError( ), 391
SetIn( ), 391
SetOut( ), 391–392
SetValue( ), 670
Sheridan, Mike, 4
Shift operators, bitwise, 75, 81–83
short value type, 38, 39, 40, 406, 647
Sign flag, 39
Sign( ), 644
Signature of a method, 195
Simple types, 37
Single .NET structure, 406, 407, 647, 649
fields, table of, 651
methods, table of, 649–650
Sinh( ), 644
sizeof operator, 615
Sleep( ), 738, 739, 779, 786, 789
Sort( ), 670, 671, 672–675, 825, 826, 829, 850–851
Sort<TKey,TValue>( ), 671, 672
SortedDictionary<TKey,TValue> class, 849, 859–861
methods, table of some, 860
performance characteristics, 862
SortedDictionary<TKey,TValue> .KeyCollection class, 860
SortedDictionary<TKey,TValue> .ValueCollection class, 860
SortedList class, 824, 833–835, 875, 879
methods, table of common, 834
SortedList<TKey,TValue> class, 849, 861–864
methods, table of some, 863
performance characteristics of, 862
SortedSet<T> class, 849, 868–869
SpinLock, 781
SpinOnce( ), 780
SpinUntil( ), 780
SpinWait structure, 780–781
Split( ), 708–711
SQL (Structured Query Language), 565, 601
Stack
memory region, 616
Stack class, 817, 824, 836–838
methods, table of, 836
methods, table of, 864
stackalloc, 616
StackOverflowException, 616
StackTrace property of Exception, 359–360
Start( ), 737, 738, 781, 784, 785, 792, 808
parameterized version of, 745, 747
StartNew( ), 792, 796, 797, 798, 799, 801
empty, 100
Statements, control, 28
selection, 87–94
static, 22, 160, 213–220, 260, 302
Status property, 905
StatusCode property, 909
StatusDescription property, 909
Stopwatch class, 808
Stream(s)
binary, 375
character, 371, 372, 374, 375, 380, 387–390
classes, byte, 373
definition of, 371
memory-based, 400–402
predefined, 371–372
redirecting standard, 372, 379, 390–392, 402
wrapper classes, character, 374–375
Stream class, 372–373, 380, 400
byte steam classes derived from, 373
methods, table of common, 372
properties, table of, 373
StreamingContext, 360
StreamReader class, 375, 387, 389–390, 633
StreamWriter class, 375, 387–389, 391
string
alias for System.String, 163, 691
class. See String class
String class, 158–166, 691–715
comparison methods, table of common, 694–696
constructors, 692
Format( ) methods, table of, 719
indexer, 693
search methods, table of, 705–707
string handling methods, table of common, 160
String(s)
comparing, 159–160, 161–163, 693–699, 881–882
culture-sensitive vs. ordinal comparisons of, 693–694, 697–699, 882
extension methods, 715
formatting. See Formatting
immutability of, 165, 691, 693
inserting, 713–714
memory-based I/O using, 402–404
numeric, converting, 406–409
padding, 711–712
pointers and, 613–614
relational operators and, 693
removing, 713–714
replacing, 713–714
searching, 702–707
splitting, 708–711
switch statements and, 91, 166
tokenizing, 710–711
String.Format( ). See Format( )
StringBuilder class, 165, 403, 691, 702
StringCollection class, 843
StringComparer class, 674–675, 881–882
StringComparison enumeration, 159, 694, 697, 702, 703
StringComparison .CurrentCulture, 159, 161
StringComparison.Current CultureIgnoreCase, 159
StringComparison.Ordinal, 159
StringComparison .OrdinalIgnoreCase, 159
StringDictionary class, 843
StringReader class, 375, 402–404
StringSplitOptions enumeration, 709
StringWriter class, 375, 402, 403–404
struct keyword, 334, 516, 529, 531
C# vs. C++, 339
corresponding to the built-in value types, .NET, 406–407, 646–664
default constructor of, 335
default value of, 534
and fixed-size buffers, 616–618
generic, 535–536
and inheritance, 335
partial, 623
using pointers with, 609
System, list of, 640
as value types, 319, 334, 338, 339
Subclass, 283
Subscribe( ), 689
Substring( ), 165, 582, 586, 714–715
Subtract( ), 655
Sum( ) extension method, 598–599
Sun Microsystems, 4
Superclass, 283
SuppressFinalize( ), 683
Suspend( ), 778
enumerations and, 91, 340, 343
and no fall-through rule, 93–94, 109
Symbol, #define directive, 464
SymmetricExceptWith( ), 848
using an event synchronization object, 769–772
using the Interlocked class, 772–773
using a lock statement, 750–755, 760, 762
using the MethodImplAttribute attribute, 760–762
using Monitor methods, 755–760
using a mutex, 762–766
and race conditions, 760
using a semaphore, 762, 766–769
SynchronizationLockException, 756
Synchronized( ), 825, 826, 831, 833, 834, 836, 839, 841
SynchronizedCollection<T> class, 848
SynchronizedKeyedCollection <K,T> class, 848
SynchronizedReadOnlyCollection <T> class, 848
Synchronous vs. asynchronous Internet communication, 898–899
SyncRoot property, 663, 820, 841
Syntax errors, 23
System namespace, 22, 345, 360, 361, 371, 372, 404, 449, 545, 601, 637, 639, 692, 784, 907
members, lists of, 639–641
System.Attribute. See Attribute class
System.AttributeUsageAttribute class, 503
System.Collections namespace, 663, 818, 823, 843
See also Collection(s)
System.Collections.Concurrent, 818, 869
System.Collections.Generic, 566, 663, 818, 844, 848, 849
System.Collections.ICollection
interface. See ICollection interface
System.Collections.IEnumerator interface. See IEnumerator interface
System.Collections.ObjectModel namespace, 818
System.Collections.Specialized namespace, 818, 843
System.Delegate, 420
System.Diagnostics namespace, 503, 781, 808
System.Diagnostics .ConditionalAttribute class, 503
System.Exception class. See Exception class
System.Globalization namespace, 160, 647, 657
System.IComparable interface. See IComparable interface
System.IDisposable interface, 632, 633
System.InvalidOperation Exception. See InvalidOperation Exception
System.IO namespace, 372, 373, 380, 449, 903
System.IO.Stream class. See Stream class
System.Linq namespace, 567, 581, 604, 715, 720
System.Linq.Enumerable, 594, 820
System.Linq. ParallelEnumerable, 820
System.Linq.Queryable, 594, 715, 820
System.Linq.Expressions. Expression<TDelegate>, 601
System.Math class, 40, 195, 213
See also Math class
System.Net namespace, 895, 898, 903
classes, list of, 896
enumerations, list of, 897
interfaces, list of, 897
Internet networking using members of the, 895–920
System.Net.Mail namespace, 895
System.Net.Security namespace, 895
System.Net.Sockets namespace, 895
System.Nullable<T> class, 618–619
System.Object class, 314
See also object class
System.ObsoleteAttribute, 505
System.Predicate, 677
System.Reflection namespace, 475, 477
System.Reflection.MemberInfo class, 475
See also MemberInfo class
System.Runtime. CompilerServices namespace, 760
System.Runtime.InteropServices namespace, 634
System.Runtime.Serialization namespace, 360
System.Security .SecurityException, 904
System.ServiceModel.UriScheme KeyedCollection, 848
System.String class, 163, 641, 691
See also String class
System.Text namespace, 165, 691, 692
System.Threading namespace, 737, 755, 780, 783, 798
System.Threading.Mutex class, 762
System.Threading.Semaphore class, 767
System.Threading.Tasks namespace, 783, 784
See also Type class
System.ValueType class, 335
System.Web namespace, 895
Tanh( ), 644
TargetSite property of Exception, 359–360
Task class, 784, 787, 791, 792, 794, 796, 798, 799
Task Parallel Library (TPL), 7, 735, 780, 783–812
and the cancellation subsystem, 780, 798
cancelling a, 798–801
child, 801
continuation, 794–796
creating and starting, 784–787, 792
and deadlock, 791
to end, waiting for a, 786, 789–791
ID, 787–789
lambda expression as a, using a, 792–794
named method as a, using a, 785, 792
nested, 801,
returning value from a, 796–797
vs. thread, 784
TaskCreationOptions class, 801
TaskFactory class, 792, 796, 801
TaskFactory<TResult> class, 796
TaskScheduler class, 801
TextReader class, 374–375, 377, 387, 391, 402, 633
input methods defined by, table of, 374
TextWriter class, 374–375, 379, 387, 391, 402
this, 135–137
and extension methods, 602
and overloaded constructors, 199–201
and static methods, 214
Thread class, 737, 738, 739, 742, 747, 748, 779, 781, 784, 801
Thread.Abort( ). See Abort( )
Thread.Resume( ), 778
Thread.Sleep( ). See Sleep( )
Thread.Suspend( ), 778
Thread.WaitHandle class, 763, 767
Thread(s)
argument to, passing an, 745–747
and the cancellation
communication, 756–760
creating and starting, 737–742
end of, determining the, 742–745
foreground and background, 736, 747
multiple child, 740–742
possible states of, 736
priorities, 747–750
and race conditions, 760
state, determining, 779
suspending and resuming, 778
synchronization. See Synchronization
task vs., 784
terminating, 774–778
ThreadAbortException, 774, 775, 777
ThreadPriority enumeration, 748
ThreadStart delegate, 737, 745
ThreadState
enumeration, 779
property, 779
ThreadStateException, 737, 743
ThrowIfCancellationRequested( ), 798, 799–800
Timeout property, 900
custom placeholder characters, table of, 731
ToArray( ), 826, 830, 836, 839, 851, 864, 866, 869
extension method, 600–601
ToBoolean( ), 680
ToByte( ), 655
ToChar( ), 680
ToCharArray( ), 585
Token
string, 710
Token property, 798
ToList( ) extension method, 600–601
ToLower( ), 160, 657, 660, 714
ToOACurrency( ), 656
ToSByte( ), 656
ToString( ), 314–315, 317, 359, 403, 404, 405, 648, 650, 652, 656, 660, 662, 681, 685, 688, 700, 701–702
used to format data, 715, 719, 721–722, 728
TotalSeconds property, 808
ToUpper( ), 160, 657, 660, 714
TrimExcess( ), 851, 863, 864, 866
TrimToSize( ), 826, 827, 834, 839
True and false in C#, 44
True displayed as bool value output by WriteLine( ), 45
TrueForAll<T>( ), 672
TrueString field, 662
try block(s), 346–352
nested, 354–355
TryEnter( ), 755–756
TryGetValue( ), 846
TryParse( ), 409, 649, 650, 652, 656, 660, 662
Tuple class, 685
Two’s complement, 39
Type(s), 25
anonymous, 201, 202, 269, 589–591
casting. See Casts
checking, 37, 51, 57, 318, 590, 626
closed, 511
constrained, 516. See also Constraint(s)
constructed. See Constructed type
data. See Data types
identification, runtime, 471–475
inference, 428, 538, 539, 569–570
metadata, 469
nullable, 38, 530, 531, 618–623
open, 511
parameterized, 507
primitive, 37
promotion, 61–62
reference. See Reference types
referent, pointer’s, 606, 610, 611
and reflection, 475–495
safety and generics, 507, 508, 510, 511–514, 518, 538, 539, 541, 564, 663, 673, 686, 818, 819, 844, 874, 875
simple, 37
value. See Value types
and constraints, 515–533. See also Constraint(s)
and pointer types, 564
to call a generic method, using explicit, 539
commonly used methods defined by the, list of, 476
commonly used properties defined by the, list of, 476
Type conversion, 44, 57–64, 620
and the as operator, 472–474
and dynamic, 627
implicit (automatic), 57–58, 61, 192–194
Type parameter(s), 509–510, 564
comparing instances of a, 544–548
and constraints, 515–516
covariance and contravariance in generic, 555–563
creating a default value of a, 534–535
and generic class hierarchies, 549–552
and generic delegates, 539
and generic interfaces, 541, 543, 544
and generic methods, 536–539
overloading methods that use, 553–554
relationship between two, establishing a, 516, 532
typeof operator, 474–475, 479, 488
uint value type, 38, 39, 40, 407, 647
literal, 48
UInt16 .NET structure, 407, 647
UInt32 .NET structure, 407, 647
UInt64 .NET structure, 407, 647
ulong value type, 38, 39, 407, 647
literal, 48
Unboxing, 315–317
unchecked keyword, 368–370
Transformation Format (UTF), 657
UTF-16 and UTF-32
characters, 657
Uniform Resource Identifier (URI), 897, 898
constructing a, 907
dissecting a, 907–908
Uniform Resource Locator (URL), 897
UnionWith( ), 848
Unmanaged
memory, 684
UnmanagedMemoryStream class, 373
/unsafe compiler option, 606
unsafe keyword, using, 607–608
UploadData( ), 918–919
UploadFile( ), 919
UploadString( ), 919
UploadValues( ), 919
UriFormatException, 904
UseDefaultCredentials property, 900, 917
ushort value type, 38, 39, 40, 407, 647
using directive
to bring a namespace into view, 22, 24, 453–455
to create an alias, 455–456
ValidOn property, 503
value
contextual keyword, 34
implicit parameter, 254, 256–257, 263, 437, 440
Value property, 619, 823–824, 848, 853, 858, 861, 884, 910
boxing and unboxing, 315–317
and call-by-reference, 178–183
new and, 132–133
null and, 530
and nullable types, 618
passed to methods, 176–177
simple type category of, 37, 38
structures as, 319, 334, 338, 339
structures corresponding to the built-in numeric, .NET, 406–407, 646–664
table of C#, 38
Values property, 822, 832, 834, 846, 858, 860, 862
Values<TValue> property, 846
used with queries, 567, 568, 570, 591
Variable(s)
const, 632
declaration, 25, 26, 29, 51, 55
definition of, 24
dynamic initialization of, 52–53
implicitly typed, 7, 26, 53–54, 567, 568, 589, 591
instance. See Instance variables
member, 12
names, rules governing, 34–35
pointer. See Pointer(s)
reference. See Reference variable(s)
scope and lifetime of, 54–56
volatile, 632
virtual keyword, 302, 305, 309
Virtual
methods, 299, 302–309, 313, 552–553
properties, 305
Visual Studio IDE (Integrated Development Environment), 14, 15–21, 921, 923
methods, returning from, 121–122
volatile modifier, 632
vsvars32.bat file, 15
Wait( ), 755–759, 779, 789–791, 792
WaitAll( ), 791
WaitAny( ), 791
WaitForExit( ), 782
WaitForFullGCApproach( ), 684
WaitForFullGCComplete( ), 684
WaitForPendingFinalizers( ), 684
WaitOne( ), 763, 766, 767, 770, 772
warning #pragma option, 469
Warth, Chris, 4
Web crawler
definition of, 913
example program, 913–916
WebClient class, 896, 897, 916–920
methods, table of synchronous, 918–919
properties, table of, 917
WebExceptionStatus enumeration, 905
WebHeaderCollection collection, 908
WebRequest class, 897, 898, 899–900, 901–904, 913, 917, 920
methods, table of commonly used synchronous communication, 899
properties, table of, 900
WebResponse class, 897, 898, 899, 900–904, 905, 908, 913, 917, 920
methods, table of commonly used, 901
properties, table of, 901
where clause, 516, 517, 518, 524, 529, 532, 533
in a LINQ query, 567–568, 571–572
Where( ) extension method, 594, 595–596
Widening conversion, 57–58
WithCancellation( ), 814
WithDegreeOfParallelism( ), 816
WithExecutionMode( ), 816
Write( ), 26, 372, 374, 379, 385, 393
WriteLine( ), 23, 26, 27, 43, 50, 315, 359, 374, 379, 402, 403, 404, 406, 662
and bool values, 45
formatted output version of, 45–48, 715, 716, 723–725
and string objects, 159
using a method within, 124
WriteTimeout property, 373
XML, 565
XML comment, 921
tags, table of, 922
XML file containing, 923–924
XOR (exclusive OR) operator (^)
Xor( ), 921
yield
break statement, 889
return statement, 888
statements, multiple, 890
Yield( ), 781
Zero field, 657