special characters - springer link

52
1231 Index Special Characters -- operator, 88 #define directive, 854–855, 857 #define symbol, 854 #endif directive, 854–855 #if DEBUG directive, 856 #if directive, 854–855 % operator, 88 %= operator, 89 & operator, 88 && (AND) operator, 50, 88, 875 &= operator, 89 * operator, 88 *= operator, 89 ... (ellipsis) button, 1076 :: operator, 87 [ ] operator, 87 | operator, 88 || (OR) operator, 88, 875 ~ operator, 88 + operator DateTime, 727 overview, 88 TimeSpan, 719 + prefix, 97 ++ operator, 88 += (increment operator), 72, 88–89 < operator DateTime, 727 overview, 88 TimeSpan, 719 << operator, 88 <<= operator, 89 <= operator DateTime, 727 overview, 88 TimeSpan, 719 <asp> tag, 1101 <asp:Button> tag, 1100 = (equals sign) operator, 39, 46, 88 /= operator, 89 != operator DateTime, 727 overview, 89 TimeSpan, 719 == operator DateTime, 727 overview, 88 TimeSpan, 719 => operator, 89 > operator DateTime, 727 overview, 88 TimeSpan, 719 >= operator DateTime, 727 overview, 88 TimeSpan, 719 >> operator, 88 >>= operator, 89 . (dot) operator, 39, 87, 140, 148–149, 176– 177 ; (semicolons), 39, 54 ( ) operator, 87 \ format component, TimeSpan, 722 / operator, 88 - operator DateTime, 727 overview, 88 TimeSpan, 719 - prefix, 97 0x prefix, 97 10 parameter, 308 20 parameter, 308

Upload: khangminh22

Post on 21-Apr-2023

1 views

Category:

Documents


0 download

TRANSCRIPT

1231

Index

� Special Characters -- operator, 88 #define directive, 854–855, 857 #define symbol, 854 #endif directive, 854–855 #if DEBUG directive, 856 #if directive, 854–855 % operator, 88 %= operator, 89 & operator, 88 && (AND) operator, 50, 88, 875 &= operator, 89 * operator, 88 *= operator, 89 ... (ellipsis) button, 1076 :: operator, 87 [ ] operator, 87 | operator, 88 || (OR) operator, 88, 875 ~ operator, 88 + operator

DateTime, 727 overview, 88 TimeSpan, 719

+ prefix, 97 ++ operator, 88 += (increment operator), 72, 88–89 < operator

DateTime, 727 overview, 88 TimeSpan, 719

<< operator, 88 <<= operator, 89 <= operator

DateTime, 727 overview, 88 TimeSpan, 719

<asp> tag, 1101 <asp:Button> tag, 1100 = (equals sign) operator, 39, 46, 88 /= operator, 89 != operator

DateTime, 727 overview, 89 TimeSpan, 719

== operator DateTime, 727 overview, 88 TimeSpan, 719

=> operator, 89 > operator

DateTime, 727 overview, 88 TimeSpan, 719

>= operator DateTime, 727 overview, 88 TimeSpan, 719

>> operator, 88 >>= operator, 89 . (dot) operator, 39, 87, 140, 148–149, 176–

177 ; (semicolons), 39, 54 ( ) operator, 87 \ format component, TimeSpan, 722 / operator, 88 - operator

DateTime, 727 overview, 88 TimeSpan, 719

- prefix, 97 0x prefix, 97 10 parameter, 308 20 parameter, 308

� INDEX

1232

� A Abort( ) method, 704 abstract classes, 71, 213

creating, 178–179 implementing, 370–371

abstract keyword, 73, 178, 211, 259, 299, 360, 371, 375

abstract methods, 71, 259, 299–301 abstract modifiers, 71, 213, 259 abstract property, 213 AbstractCalculator class, 259, 371 AcceptTcpClient method, 687 access modifiers, 69, 133, 180–181, 210–211,

257 Action class, 326, 401, 773 Action column, 1220 Action delegates, 326–328, 330, 401 Action parameter, 772, 776, 796 Action type, 328 Action variable, 326 Action<int, int> delegate, 327 Action<T> class, 571 Action<T1, T2, T3, T4, T5> type, 328 Actions event, 64 ActualValue property, 434 Adam Freeman argument, 138 Add Connection menu item, 1002 Add method, 446, 556–557, 578, 583, 678,

942, 996, 1026, 1093 Add New Domain Service Class dialog box,

1142–1143 Add New Project dialog box, 1099 Add Reference context menu option, 753,

760 Add Reference dialog box, 753, 760, 1009 Add Service Reference context menu

option, 697 Add Service Reference dialog box, 699 AddAfter method, 577 AddAfter(LinkedListNode<T>, T) method,

577 AddBefore method, 577 AddBefore(LinkedListNode<T>, T) method,

577 AddDays(double) method, DateTime, 729 AddFirst method, 577 AddFirst(object) method, 942 AddFirst(T) method, 577 AddHeader(string, string) method, 704

AddHours(double) method, DateTime, 729 Addition operator, 110 AdditionHelper class, 343, 345 AddLast method, 577 AddMilliseconds(double) method,

DateTime, 729 AddMinutes(double) method, DateTime,

729 AddMonths(int) method, DateTime, 729 AddObject method, 942, 993, 996 AddRange(IEnumerable<string>) method,

557 AddressList property, 709 AddSeconds(double) method, DateTime,

729 Add(T) method, 553, 595 AddTicks(long) method, DateTime, 729 Add(TimeSpan) method, DateTime, 729 Add(TKey, TVal) method, 582, 586, 590 AddYears(int) method, DateTime, 729 ADO.NET, 28–29 Aero Glass, 1063–1067 Aes class, 1187 AesCryptoServiceProvider class, 1187 AesManaged class, 1187, 1191 age field, 750, 752 age parameter, 276–279 Age property, 278, 479 AggregateException class, 446–448, 450–

451 aggregating

data, with LINQ, 905–910 exceptions, 446–451

Albahari, Joseph, 27 aliases, disambiguating namespaces with,

349–350 Aliases property, 709 aliasing

generic types, 839–840 namespaces, 350–351

alignment, specifying, 509–510 All value, 536, 647 AllDirectories value, 626 AllKeys property, 681 AllocateResources method, 431 AlternateCalculator class, 314 AlternateListener class, 312 AND (&&) operator, 50, 88, 875 animations, 1086–1090

adding, 1087–1089 combining multiple, 1089–1090

� INDEX

1233

creating projects, 1087 testing, 1089

anonymous methods, 329–333 types, 478, 889–890

antecedent, getting details of, 797–798 App.config file, 972, 1008–1009 Append methods, 65, 503, 505–506 Append value, 660 AppendAllLines(string,

IEnumerable<string>) method, 640 AppendAllText(string, string) method, 640 AppendChar method, 1199 AppendChar(char) method, SecureString

class, 1199 AppendFormat(string, object) method, 503 AppendFormat(string,params object)

method, 503 AppendLine( ) method, 503 AppendLine(string) method, 503 Append(string) method, 503 AppendText( ) method, 634 AppendText(string) method, 642 apple.jpg file, 704 Application class, 1035, 1048, 1155 Application Configuration File template,

1008 Application template, Silverlight, 1126 ApplicationCommands class, 1093 ApplicationCommands.New argument,

1093 Application.Current property, 1156 Application.InstallState property, 1155 Application.Run method, 1035 applications, customizing, 1116–1124

changing names and visibility of columns, 1119–1120

changing table names, 1117–1118 customizing display template, 1122 selecting tables to be displayed, 1120–

1121 arbitrary types, creating XElements using,

928–930 ArgumentNullException class, 434 ArgumentOutOfRange exception, 207, 788–

789, 794 ArgumentOutOfRangeException class, 424–

425, 434, 450 arguments, indexers with, 218–219 ArguumentOutOfRange exception, 788 arithmetic operators, 109–113

arithmetic overflow keywords, 78 arrange variable, 911 Array class, 883 array parameter, 433 Array.Copy method, 404 Array.FindAll method, 407–408 Array.ForEach method, 401–402 ArrayList class, 617–619, 902 arrays, 385–418

of arrays, 415 defining and initializing, 387–389 enumerating, 393–399

breaking from enumerations, 398–399

with a foreach loop, 395–396 with a for loop, 393–395 using IEnumerator and

IEnumerator<T>, 396–398 getting and setting values, 389–391 initializers, 391–392 jagged, 415–418

enumerating, 417–418 getting and setting values, 416–417 initializers, 417

of parameters, 247–249 rectangular, 410–415

creating with additional dimensions, 414–415

enumerating, 412–413 getting and setting values, 411 initializers, 411–412

System.Array members, 400–408 finding items in arrays, 406–408 processing elements in arrays, 401–

402 resizing and copying arrays, 402–406 sorting arrays, 400–401

treating as collections, 609–612 using as collections, 409 using with LINQ, 408

Array.Sort method, 400 as keyword, 618 as object keyword, 83 as operator, 172–173, 461–462 ASCII property, 850 AsEnumerable( ) method, 1018 AsEnumerable<T> method, 398 AsOrdered method, 920 AsParallel method, 915, 917, 920–922

� INDEX

1234

ASP.NET, 1099–1124 building Web Forms program, 1099–

1108 adding controls, 1102–1104

ASP.NET (cont.) creating projects, 1099–1102 setting control properties, 1104–1106 setting focus, 1107–1108 setting tab order, 1106 testing, 1108 wiring Button control, 1107

Dynamic Data, 1113–1124 changing names and visibility of

columns, 1119–1120 changing table names, 1117–1118 creating Entity Data Model, 1114 creating projects, 1113 customizing display template, 1122 registering data model, 1114 selecting tables to be displayed,

1120–1121 testing, 1114–1116

understanding, 26 using Web Forms data binding, 1108–

1113 adding GridView control, 1111–1112 adding web form, 1109 creating projects and Entity Data

Model, 1109–1113 creating web forms data source,

1109–1111 testing, 1112–1113

ASP.NET Dynamic Data Entities Web Application template, 1113

AsReadOnly( ) method, 572, 575, 614 assemblies, 20–22 AssemblyFormat property, 750 Assert dialog box, 1206 Assert method, 1204, 1206–1210, 1225 Assert statement, 1206 Assert(bool, string) method, 1209 Assert(bool, string, string) method, 1209 Assert(bool, string, string, params object[])

method, 1209 Assert(bool) method, 1209 assertions

contracts, 1224–1225 making, 1204–1206

assignment operators, 122–125 asymmetric properties, 209 AsyncCompletedEventArgs class, 683–684

Asynchronous delegate, 819 asynchronous methods, 816–824

mixing with tasks, 823–824 overview, 819–820 waiting to complete, 820–823

asynchronous requests, with WebClient class, 682–684

AsyncMethodCallback method, 820 AsyncWaitHandle.WaitOne method, 815 Attibutes( ) method, 938 attributes, 519–538

custom, creating, 532–538 controlling, 535–537 defining properties in, 535 using, 533–535

testing for, 522–532 applied to classes, 522–525 applied to fields, 525–527 applied to methods, 530–532 applied to properties, 528–529

using, 519–522 Attributes value, 650 Attributes(string) method, 938 AttributeTarget enum, 536 AttributeTester method, 525 AttributeTester<T> class, 523, 525, 528, 530 AttributeTester.GetModifiedFields method,

527 AttributeUsage attribute, 535, 537 AuditSystem namespace, 352 AuditSystem.System class, 352 automatic memory management, 23 automatically implemented properties, 208 AutoSizeColumnsMode property, 1057 Average( ) method,

System.Linq.Enumerable class, 905

� B B alias, 351 BackgroundColor property, Console class,

846–847 base class fields, hiding, 199–201 base keyword, 84–85, 264, 266–267, 281, 300 base streams, 657–662

FileStream class, 660–662 MemoryStream class, 657–659

base structs, and inheritance, 375 BaseAddress property, 677 BaseCalculator class, 299, 366, 370

� INDEX

1235

BaseClass class, 263 BaseClass variable, 263 baseDir variable, 701 base.myField field, 200 base.PrintCarDetails( ) method, 156 BaseProduct local variable, 201 BaseType<T> class, 472 Beep method, for Console class, 846 Beep(int, int) method, 846 Begin method, 815, 817–818, 820, 823 Begin value, 655 BeginAnimation method, 1088–1089 BeginInvoke method, 815, 820–821 Bicycle class, 170, 172 bigint type, 976 bigInt variable, 126 bigInt2 variable, 126 BigInteger class, 126–127 Bill class, 348 BillingProduct class, 350 BillingSystem namespace, 347–348, 351 BillingSystem.Bill class, 348 BillingSystem.Product class, 347–348, 350 binary data

reading, 667–669 writing, 667–669

binary operators, 221–224 binary searches, finding list items using,

560–561 binary serialization, 736–752

callback attributes for, 745–747 graphs of objects, 739–741 multiple objects to single stream, 741–

744 selected fields only, 744–745 version tolerance for, 748–752

BinaryFormatter class, 339–340, 738, 748, 751, 754

BinaryReader class, 667–669 BinarySearch method, 560–561, 569–570 BinarySearch(int, int, T, IComparer(T))

method, 559 BinarySearch(T, IComparer(T)) method, 559 BinarySearch(T) method, 559 BinarySearch(T[], T, IComparer<T>)

method, 611 BinarySearch(T[], T) method, 611 BinaryWriter class, 667–668 bin\Debug directory, 271, 702, 704, 1063,

1206 binding, 1092–1093

BindingNavigator control, 1056 BindingSource control, 1056, 1058, 1060 BingInteger class, 127 bin\Release directory, 271, 702, 704, 1063,

1206 BirthDate column, 1120 Black argument, 138 Bock, Jason, 1185 bodies, of methods

defining, 237–238 local variables, 251–256 using method results, 256–257

bool field, 127 bool keyword, 62, 127, 129 bool parameter, 631, 670, 845, 1121, 1204,

1210, 1225 bool results, 128 bool type, 116, 127–129, 240, 389 bool values, 43, 118, 128, 669 bool variables, 48, 50, 128 Boolean type, 127–130

literals, 127–128 results, 128–129 struct members, 129–130

Boolean values, grouping data with for LINQ, 887–888

boxing objects, 173–175 braces, escaping, 510–511 Break( ) method, ParallelLoopState class,

828 break jump keyword, 76 break keyword, 292, 399, 406, 827 Break method, ParallelLoopState class, 829 break statement, 52, 55 breaking parallel loops, 827–831 buffered pass-through stream, 663–664 BufferedStream class, 663 Build menu, 14, 1215 Build Solution menu option, 14 Button

click event, 1080 configuring, 1076 controls

configuring, 1091–1092, 1106 for Swimming Calculator example,

1134 wiring, 1107

Windows Forms example program with configuring, 1041 events for, 1051–1053

wiring, 1080–1085

� INDEX

1236

Button.WidthProperty, 1089 by keyword, 886 byte array, 640, 657–659, 669 byte keyword, 62, 92 byte type, 93–94, 98–99, 101, 118 byte values, 43, 654, 656, 659, 669 bytes, converting to strings, 849–850

� C C component, 513–514 C#, 22–29

automatic memory management, 23 Cross-Platform Support, 29 Just-In-Time Compiler (JIT), 23 .NET technology Spectrum, 24–29

ADO.NET, 28–29 ASP.NET, 26 LINQ, 26–27 Task Parallel Library (TPL), 27 user interfaces, 27–28 Windows Communication

Foundation (WCF), 29 object-orientation, 22 overview, 17–18 parallel processing, 23–24 program, 33–34 projects, creating, 10–14 relationship with C#, 19–20 syntax, 34–41

comments, 40–41 identifiers, 34–36 keywords, 37 literals, 37 operators, 38–39 punctuators, 39–40 statements, 40

type safety, 22–23 Unmanaged/Native Code Support, 24

CalaculationException class, 441 CalaculationParameterRangeException

class, 444 calc variable, 524 CalcDelegate property, 308 calcProduct parameter, 256 CalculateDivision method, 1203–1204, 1216,

1222 CalculateFuelForTrip method, 135, 137,

148–149, 154, 159–161, 164 CalculateMethod method, 307

CalculateProduct method, 72, 237, 259, 307, 310, 319, 357–358, 363, 522

CalculateSubtraction method, 1216 CalculateSum method, 80, 259, 267, 357,

363, 370, 790–791, 1216, 1218 CalculateXXX method, 1226 calculationCount variable, 332–333 CalculationEventArgs class, 318–319, 330 CalculationException class, 440–441 CalculationListener class, 312 CalculationListener.CalculationPrinter

method, 310 CalculationParameterRangeException class,

444 CalculationPerformedEvent event, 72, 318 Calculator class, 247, 258, 288, 308, 325, 357,

525, 1203, 1219, 1222 Calculator constructor, 307 Calculator delegate field, 316 Calculator event, 321 Calculator.CalculateProduct method, 310 Calculator.CalculationPerformed field, 316 CalculatorImpl class, 696, 698 Calculator.PerformCalculation method, 446 CalculatorServerClient class, 699 CalculatorSum method, 357 CalculatorTest class, 1203 callback method, 817 callbacks

attributes, for binary serialization, 745–747

using delegates for, 308–310 caloriesTextBox control, 1078 Camel case style, 35 Cancel method, 784, 787 CancellationTokenSource class, 783–784,

786–787 CancellationToken.ThrowIfCancellationReq

uested method, 784 CancellationToken.Token property, 783 Cancelled property, 684 cancelling Task class

multiple tasks, 786–787 in single statement, 784–786

CanExecute method, 1095 CanExecute property, 1095 CanRead property, 651, 653 CanSeek property, 651, 653–654 CanWrite property, 651, 653 Capacity method, 503 Capacity property, 572–573, 585, 658

� INDEX

1237

capitalization styles, 35–36 case keyword, 75 case labels, 494 case selection keyword, 75 case statements, 52 cast exceptions, explicit, 170–173

casting without exceptions, 172–173 testing an object types, 170–172

Cast method, 903 casting

implicit vs. explicit, 165–169 objects without exceptions, 172–173 from parameterized types, 461–462

catch clauses, 425–427 general, 426 omitting, 426–427

catch exception handling keyword, 78 catch keyword, 421–422 categories, 1211–1212 CDATA block, 931 CDNs (content distribution networks), 709 Ceiling(decimal) method, 108 Ceiling(double) method, Math class, 852 chains, exception, 444–446 change, monitoring

directories, 645–650 filtering monitored, 648–649 filtering triggers for change events,

649 files, 645–650

filtering monitored, 648–649 filtering triggers for change events,

649 Changed event, 646, 648–649 Changed value, 647 ChangeExtension(string, string) method,

643 ChangeType property, 646 char array, 501–503, 643, 669, 673 char keyword, 62, 482, 484 char parameter, 485, 497 char type, 482, 484–485, 503, 976 char values, 43, 483, 669 char variable, 482–484 characters, 482–486

expressing using literals, 482–483 performing operations on, 483–484 reading, 492–493 using struct members, 484–486

CheckBox control, 1094–1095 checked arithmetic overflow keyword, 78

checked block, 102–103 checked keyword, 101–102, 113 checkers

runtime, 1229–1230 static, 1226–1228

CheckLengthAndPrintName method, 385–386

CheckRange method, 236, 239 cherry.jpg file, 704 Child Window, for Swimming Calculator

example, 1137–1140 Child Window template, Silverlight, 1138 chunked execution, 825 CIL (Common Intermediate Language), 18 class constraint, 464 class keyword, 15, 36, 63, 133, 464 Class Library, 18 class statements, 15 Class value, 536 classes, 132–150, 926–944

abstract, implementing, 370–371 adding features to, 133–136

constructors, 135–136 fields, 133–134 methods, 134–135

allowing to read and modify properties, 188–189

creating objects from, 136–139 creating XML declaratively, 926–933

creating other XML node types, 930–931

creating valid XML documents, 932–933

creating XElements using arbitrary types, 928–930

differences with structs, 374–376 base structs and inheritance, 375 fields, 375 struct constructors, 375–376

encapsulation, 159–160 generic, 456–460

creating objects from, 456–457 implementing and using members,

457–460 generic base, deriving from, 467–471

inheriting type deferral, 467–468 specifying parameterized types, 470–

471 inheritance, 153–158

inheriting derivations, 157–158 overriding methods, 156–157

� INDEX

1238

classes (cont.) members of, 496–501

manipulating strings, 496–499 other class members, 500–501 searching strings, 499–500

modifiers, 176–181 creating abstract classes, 178–179 creating partial classes, 179–180 creating sealed classes, 179 creating static classes, 176–177 using access modifiers, 180–181

modifying XML, 940–944 nested, 175–176 objects, 139–150

calling methods, 148–150 reading and modifying fields, 140–

142 references to common objects, 142–

146 using static fields, 147–148

polymorphism, 160–165 populating XElement or XDocument

with IEnumerable, 933–934 processing XML declaratively, 936–940

filtering elements by name, 938–939 finding all descendants, 939–940

reading and writing XML files, 934–936 loading XML, 936 saving XML, 934–936

StringBuilder, 502–506 testing for attributes applied to, 522–525

clauses, 51 Clear( ) method, 503, 553, 1148, 1199, 1207 Click event, 1046–1047, 1051, 1059, 1080,

1087, 1107, 1136, 1155 ClientBin folder, 1128 Close( ) method, 651, 656–657, 664, 687, 690,

703–704, 1007–1008 CLR (Common Language Runtime), 18 CLS (Common Language Specification), 20 cmd.exe item, 704 CNG (Cryptography Next Generation), 1194 C:\Northwind directory, 967, 970, 1002 code, editing, 13–14 Code Analysis tab, 1214 code block, 40 code comments, 16 code contracts, 1221–1230

installing and enabling, 1221–1222 runtime checker, 1229–1230 static checker, 1226–1228

writing, 1222–1226 assertion contracts, 1224–1225 invariant contracts, 1225–1226 postcondition contracts, 1223–1224 precondition contracts, 1222–1223

Code Contracts tab, 1222 Collect method, 540 Collection Editor dialog box, 1076 collection-backed indexer, 216 collections, 551–619

constrained, creating, 613–617 dictionaries, 585–595

Dictionary<TKey, TVal> collection class, 589–592

IDictionary<TKey, TVal> interface, 586–588

KeyValuePair<TKey, TVal> structure, 588–589

SortedDictionary<TKey, TVal> collection class, 593–595

ICollection<T> interface, 553–554 IComparer<T> interface, 606–608 IEqualityComparer<T> interface, 608–

609 legacy, 617 lists, 554–585

IList<T> interface, 555–556 LinkedList<T> collection class, 575–

581 List<T> collection class, 556–575 SortedList<TKey, TVal> collection

class, 581–585 queues, 602–606 sets, 595–602

HashSet<T> collection class, 597–599 ISet<T> interface, 595–597 SortedSet<T> collection class, 599–

602 stacks, 602–606 treating arrays as, 609–612 using arrays as, 409

CollectionViewSource class, 1083 Color element, 959, 962 Color property, 949 ColumnDefinition element, 1129 columns, changing names and visibility of,

1119–1120 Columns property, 1084 Combine(string, string) method, 643 Combine(string, string, string) method, 643 Combine(string[]) method, 643

� INDEX

1239

combining strings, 491–492 values, 383–384

ComboBox control, for WCF RIA Service, 1146–1147

ComboBox variable, 1148 Command list, 1092 Command property, 1091–1093 CommandBinding class, 1095 CommandBinding constructor, 1093 CommandBindings property, 1093 commands, 1090–1098

adding and configuring MenuItem control, 1092

binding, 1092–1093 configuring Button controls, 1091–1092 creating project, 1090–1091 selectively activating, 1094–1096 using to set control content, 1096

CommandText property, 1012 comments, 40–41 Common Intermediate Language (CIL), 18 Common Language Runtime (CLR), 18 Common Language Specification (CLS), 20 Company class, 287, 740 Company type, 287 Compare method, 606–607 Comparer property, 593 Comparer<int>.Default class, 607 Comparer<string>.Default class, 568 Comparer<T>.Default class, 566 Compare(T, T) method, 606 CompareTo method, 464 comparing strings, 489–490 comparison operator, 47–48 Compile method, 986–987 CompiledQuery class, 986 compiler, conditional compilation with,

853–857 Conditional attribute, 856–857 using Visual Studio to define symbols,

855–856 compiler-inferred types, for LINQ, 873–874 compiling queries, 985–988 ComponentCommands class, 1093 composite formatting, 507–511

escaping braces, 510–511 other methods, 508–509 specifying alignment, 509–510 TimeSpan, 720

Compress value, 665

compressing data, with pass-through streams, 664–666

CompressionMode enumeration, 665 computed properties, 209–210 ComputeHash method, 1194–1196 Concat(string, params string) method, 496 concurrency checking, enabling, 999 Concurrency Mode property, 999 concurrent collections, parallel

programming using, 809–813 ConcurrentDictionary class, 812 ConcurrentQueue class, 812 ConcurrentQueue.TryDequeue method,

813 ConcurrentStack class, 812 Conditional attribute, 856–857 conditional compilation, 853–857

Conditional attribute, 856–857 using Visual Studio to define symbols,

855–856 conditional operators, 50 Configuration Manager dialog box, 1206 ConfigurationManager class, 1010 Configure Data Source dialog box, 1110 Connection Properties dialog box, 969 connection strings, storing, 1008–1010 ConnectionState Enum, 1006 ConnectionString property, 1005 ConnectionStrings indexer, 1010 Console Application template, 11–12 Console class, 843–848

Beep method for, 846 modifying appearance of, 846–848 reading from and writing to, 843–845

Console member, 352 Console.Beep method, 846 ConsoleKey enum, 845 ConsoleKeyInfo struct, 845 ConsoleKeyInfo.Key property, 845 ConsoleModifiers enumeration, 845 Console.Out property, 1208 Console.ReadLine method, 16 Console.Write method, 845 Console.WriteLine method, 16, 255, 507–

508, 515, 572, 695, 724, 933 Console.WriteLine statements, 479, 776 const field, 196–197 const keyword, 196–197 const modifier, 71 constrained collections, 613–617

� INDEX

1240

constraining parameterized types applying multiple constrains to

parameterized types, 464 constraining multiple parameterized

types, 465 constructions, initializing properties and

fields at, 274–275 constructors, 272–290

access to, 283–284 adding to classes, 135–136 calling base class constructors, 280–283 copy, 284–287 factory methods, 289–290 initializing properties and fields at

constructions, 274–275 optional parameters in, 279–280 overloading, 275–280 static, 287–289 of structs, 375–376 TimeSpan, 715–716 using, 274

consuming namespaces, 337–340 importing namespaces, 339–340 using fully qualified names, 338–339

Contains method, 464, 471 ContainsKey(TKey) property, 585–586, 593 Contains(string) method, 499 Contains(T) method, 553 ContainsValue(TKey) property, 593 ContainsValue(TVal) property, 585 Content attribute, 1072 content distribution networks (CDNs), 709 Content property, 1074, 1076–1077, 1080,

1083, 1094, 1133, 1148 ContentLength64 property, 704 ContentType property, 704 Context property, Button control, 1134 continuations, of Task class

chains of, 800–801 results for, 798–800 selective, 801–803 simple, 796–797

continue jump keyword, 76–77 continue keyword, 56 ContinueWith method, 796–797, 800–801,

803 ContinueWith<int> method, 799 ContinueWith<T> method, 798 Contract method, 1225 Contract.Assert method, 1224 Contract.Ensures method, 1223

Contract.Invariant method, 1225 ContractInvariantMethod attribute, 1225–

1226 Contract.Requires method, 1222 Contract.Result<int>( ) method, 1224 Contract.Result<T> method, 1224 contracts

assertion, 1224–1225 invariant, 1225–1226 postcondition, 1223–1224 precondition, 1222–1223

contravariance, 476–477 control statements, 40 controls

adding, 1072–1074 Button

configuring, 1091–1092 wiring, 1107

content, 1096 DataGrid, formatting, 1084–1085 focusing on first, 1081 GridView, adding, 1111–1112 Label, 1074 MenuItem, adding and configuring,

1092 setting properties, 1074–1076, 1104–

1106 configuring Button, 1076–1106 configuring Label controls, 1074 configuring labels, 1104 configuring TextBlock controls, 1075 configuring TextBox controls, 1074–

1075, 1104–1106 TextBlock, 1075 TextBox, 1074–1075, 1079–1080, 1104–

1106 wiring, 1078–1081

Button, 1080–1081 Quit menu, 1078–1079 TextBox controls, 1079–1080

convenience methods, System.IO.File class, 640–642

conversion operators, 219, 225–227 Convert class, 834, 836 Convert ToXXX method, 835 ConvertAll method, 573, 612 ConvertAll(TIn[], TOut[], Converter<TIn,

TOut>) method, 611 convertButton control, 1078 convertButton_Click method, 1140, 1154 Converter<string, int> class, 612

� INDEX

1241

converting results with LINQ, 899–901 types, 834–836

Convert.ToBase64String method, 1188 ConvertToBinary method, 121 Convert.ToString method, 118 copy constructor, 284–287 Copy method, 404–405 copying structs, 376–380 Copy(string, string) method, 639 Copy(T[], T[]) method, 611 CopyTo method, 405, 574 CopyTo(Stream) method, 651 CopyTo(string, bool) method, 631 CopyTo(string) method, 631 CopyTo(T[], int, int) method, 572 CopyTo(T[], int) method, 553, 572 CopyTo(T[]) method, 572 Cos(double) method, Math class, 852 Count( ) method, System.Linq.Enumerable

class, 905 Count method, 897–899 Count property, 446, 553, 572–573, 585, 593,

603, 605, 811, 980 Counter class, 291–292, 294–295 covariance, 475–477 C:\Program Files directory, 627 cratesInStock field, 191 cratesinStock field, 191 CratesInStock property, 191 Create( ) method, 634–635, 653, 838,

1198 Create New Complex Type button, 991 Create value, 660 CreateCommand method, 1012 CreateCustomer method, 994 Created event, 646 Created value, 647 CreateDecryptor method, 1190 CreateEmployee method, 994 CreateEncryptor method, 1190 CreateNew value, 660 Create(string) method, 642 CreateSubDirectory(string) method,

635 CreateText( ) method, 634 CreateText(string) method, 642 CreateXXX method, 994, 996 CreationTime property, 631, 635, 637 CreationTime value, 650

critical region, and sharing data between tasks, 806

Cross-Platform Support, 29 cryptography. See data encryption Cryptography Next Generation (CNG),

1194 CryptoStream class, 1189–1190 CryptoStreamMode enumeration, 1190 .cs file extension, 19 CSV data, creating XML from, 953–954 CSV files, creating from XML, 952–953 curly braces, 39 Current method, 397–398 Current property, 397–398, 867–868, 1078,

1155 Current value, 655 CurrentDirectory property, Environment

class, 850 CursorVisible property, Console class, 846 custom attributes, creating, 532–538

controlling, 535–537 defining properties in, 535 using, 533–535

custom composite formatting, 516 custom data, events without, 323–324 custom exceptions

creating and throwing, 438–441 escalation policy, exceptions from

trigger method using, 794–795 Customer and Suppliers by City view, 988 Customer class, 994 Customer_and_Suppliers_by_City type, 989 Customers property, 984–985, 996 Customers table, 982 Customers_By_City procedure, 990, 992

� D D component, 513 d format component, DateTime, 732 D format component, TimeSpan, 722 D specifier, DateTime, 730 D suffix, 96 data

deleting, 998–999 downloading, 10 inserting into databases, 993–996 loading, 1085 navigation, 983–985 querying, 985–993

� INDEX

1242

data (cont.) compiling queries, 985–988 querying stored procedures, 989–993 querying views, 988–989 XML for, 945

updating in databases, 996–997 data binding, 1083–1086, 1108–1113

adding GridView control, 1111–1112 web form, 1109

creating projects and Entity Data Model,

1109–1113 web forms data source, 1109–1111

formatting DataGrid control, 1084–1085 loading data, 1085 testing, 1086, 1112–1113 with Windows Forms, 1053–1062

creating object data source, 1054–1056

creating project, 1053–1054 displaying data fields, 1061–1062 filtering with LINQ, 1060–1061 formatting DataGridView control,

1056–1058 loading data, 1058 testing, 1059–1060 wiring save button, 1058–1059

wiring Button, 1085 Data Connections item, Server

Explorer/Database Explorer window, 1002

Data Contract Serializer, 760–765 generating

JSON (JavaScript Object Notation), 763–764

.NET-specific XML, 762–763 portable XML, 761–762

preparing class for, 760–761 data encryption, 1186–1193

decrypting data, 1190–1191 encrypting data, 1189–1190 and encryption keys, 1186–1188 and hash codes, 1193–1197

generating, 1194–1196 verifying, 1196–1197

using Windows DPAPI (Data Protection API), 1191–1193

data model context, 974 registering, 1114

Data property, 428, 437–438 Data Protection API (DPAPI), 1191, 1198 data sources

creating, 1109–1111 legacy collection as, 902–904

range variable type, 902 using Cast method, 903

for LINQ (Language Integrated Query), 866–869

DataApp.Web project, 1141–1142 dataArray array, 457 dataArray field, 471 databases

inserting data into, 993–996 operations on with LINQ, 1024–1030

deleting data, 1029–1030 inserting data, 1024–1026 modifying data, 1027–1028

preparing, 967 updating data in, 996–997

DataContactSerializer class, 761 DataContract attribute, 760–761 DataContractJsonSerializer class, 764 DataContractSerializer class, 761–762 datafile.txt file, 1195 DataGrid controls

formatting of, 1084–1085 for WCF RIA Service, 1145–1146

DataGridView control, formatting of, 1056–1058

DataMember attribute, 760–761 DataProtectionScope enumeration, 1193 DataRow class, 1014 DataRowComparer.Default property, 1022,

1024 DataSet class

overview, 1012–1014 querying with LINQ, 1016–1030

for data intersects, 1021–1022 performing joins on, 1018, 1021–

1024 subtracting results, 1023–1024

DataSet.Tables property, 1014 DataSource property, 1058 DataTable class, 1014 DataTable.Rows property, 1015 data.xml file, 940, 944, 960 Date property, DateTime, 725 date type, 976 dates. See time and dates DateTime class, 628

� INDEX

1243

DateTime constructors, 724 DateTime operator, 711 DateTime parameter, 628 DateTime strings, formatting, 730–733 DateTime struct, 711, 715 DateTime type, 976 DateTime values

creating and using, 724–726 performing operations on, 727–730

DateTime.AddXXX methods, 729 DateTime.ToString method, 731 Day property, DateTime, 726 DayOfWeek property, DateTime, 725 DayOfYear property, DateTime, 725 Days property, TimeSpan, 716 dd format component, DateTime, 732 ddd format component, DateTime, 732 dddd format component, DateTime, 732 Debug build mode, 1206 Debug class, 1202–1212

Debug listeners, 1207–1209 disabling Debug statements, 1206 making assertions, 1204–1206 other Debug methods, 1209–1212

categories, 1211–1212 indenting Debug output, 1211–1212

DEBUG constant, 1214 Debug dialog box, 1230 Debug menu, 14, 16, 697 Debug method, 1221, 1223 Debug statements, 1222 DEBUG symbol, 855–856 Debug.Assert method, 1204–1205, 1209 debugging. See testing and debugging Debug.Listeners property, 1207 decimal (Floor) method, 108 decimal keyword, 63, 93 decimal type, 93, 96, 98–99, 107–108, 976 decimal values, 43, 93, 108, 669 declaration statements, 40 Decompress value, 665 Decrypt( ) method, 632 decrypting data, 1190–1191 Decrypt(string) method, 639 default keyword, 477–478 Default property, 609 default selection keyword, 75 Default.aspx file, 1100–1101, 1109, 1122–

1123 DefaultFocus property, 1108 deferred execution, of LINQ, 895–899

forcing immediate execution, 897–899 referring to variables, 896–897 reusing queries, 895–896

defining symbols, using Visual Studio, 855–856

definite assignments, 45–46 DeflateStream class, 664 del variable, 308 delegate keyword, 64, 306, 330 Delegate value, 536 delegates, 306–315

Action, 326–328 Func, 328 interrogating, 313–315 multicasting with, 310–312 selectively of, 312–313 using for callbacks, 308–310

Delete( ) method, 632, 635, 637, 1029 Delete(bool) method, 635 Deleted event, 646 Deleted value, 647 DeleteObject method, 998 Delete(string) method, 639 deleting data, databases operations with

LINQ, 1029–1030 delimited comment, 41 Dequeue( ) method, 603–604, 810–811 derivations, inheriting, 157–158 DerivedCalc class, 259, 325, 366, 370 DerivedClass class, 74, 263 DerivedClass.PrintMessage method, 264 DerivedProduct class, 200 DerivedType<T> class, 472 deriving interfaces, 362–365 DES class, 1187 descendants, finding all, 939–940 Descendants( ) method, 937–940, 943 descending keyword, 882 Description element, 940 Description property, NetworkInterface

class, 859 DESCryptoServiceProvider class, 1187 Deserialize method, 738–739, 756 Design property group, 1043 destructors, 541–543

finalizers versus, 542–543 overview, 290 problems with, 543

DetailLevel attribute, 533–538 Details.aspx file, 1122

� INDEX

1244

dictionaries, 585–595 Dictionary<TKey, TVal> collection class,

589–592 IDictionary<TKey, TVal> interface, 586–

588 KeyValuePair<TKey, TVal> structure,

588–589 SortedDictionary<TKey, TVal>

collection class, 593–595 Dictionary<string, string> class, 588 Dictionary<TKey, TVal> collection class,

589–592 Dictionary<TKey, TVal>(IDictionary<TKey,

TVal>, IEqualityComparer<TKey, TVal>) method, 590

Dictionary<TKey, TVal>(IDictionary<TKey, TVal>) method, 590

Dictionary<TKey, TVal>(IEqualityComparer>TKey>) method, 590

Dictionary<TKey, TVal>(int, IEqualityComparer<TKey>) method, 590

Dictionary<TKey, TVal>(int) method, 590 Dictionary<TKey,TVal>( ) method, 590 directories, 622–650

change monitoring, 645–650 filtering monitored directories, 648–

649 filtering triggers for change events,

649 changing current working, 629–630 DirectoryInfo class, 630–638 getting and setting information for, 628–

629 System.IO.Directory class, 622–630 System.IO.Path class, 643–644

Directory class, 622–623, 629, 637, 639 Directory property, 632 Directory.GetFiles method, 627 DirectoryInfo class, 630–638 DirectoryName property, 632 DirectoryName value, 650 disambiguating namespaces and types,

347–353 with aliases, 349–350 aliasing namespaces, 350–351 with fully qualified names, 349 resolving type or namespace hiding,

351–353

display template, customizing, 1122 DisplayName attribute, 1118, 1120 disposal, 544–545 Dispose method, 544–545, 1008 DivideByZero exception, 1206 Division operator, 109 divisor parameters, 249, 251 divisor variable, 254 .dll file extension, 20 DNS (Domain Name System), 707, 816 Dns class, 707–708, 817, 819 Dns.GetHostEntry method, 816 do Iterator keyword, 76 Document Object Model (DOM), 925 Document Outline view, 1079 Document Type Definition (DTD), 932 Document View, 1078 DOM (Document Object Model), 925 Domain Name System (DNS), 707, 816 Domain Service Class template, 1142 DoSomeWork method, 773, 779 dot (.) operator, 39, 87, 140, 148–149, 176–

177 double field, 210 double keyword, 63, 93 double types, 93–96, 98–99, 107, 977 double values, 43, 107–108, 210, 669 DoubleAnimation class, 1088 double.Parse method, 210 DoubleResultCalc class, 267–268 do...while loop, 60 DownloadData method, 680 DownloadDataAsync(Uri) method, 683 DownloadDataCompleted event, 683 DownloadDataCompletedEventArgs class,

683–684 DownloadData(string) method, 679 DownloadFileAsync(Uri) method, 683 DownloadFileCompleted event, 683 DownloadFile(string, string) method, 679 DownloadString method, 680 DownloadStringAsync method, 682 DownloadStringAsync(Uri) method, 683 DownloadStringCompleted event, 682–683 DownloadStringCompletedEventArgs class,

683–684 DownloadString(string) method, 679 DPAPI (Data Protection API), 1191, 1198 DTD (Document Type Definition), 932 Duration property, 1088

� INDEX

1245

Dynamic Data, 1113–1124 creating

Entity Data Model, 1114 projects, 1113

customizing applications, 1116–1124 changing names and visibility of

columns, 1119–1120 changing table names, 1117–1118 customizing display template, 1122 selecting tables to be displayed,

1120–1121 registering data model, 1114 testing, 1114–1116

Dynamic Data Entities Web Application template, ASP.NET, 1113

dynamic keyword, 64–65, 69 dynamic reference type, 44 DynamicData\PageTemplates folder, 1122

� E E component, 513 E method, Math class, 852 e parameter, 892 Edit Columns dialog box, 1057 Edit.aspx file, 1122 EditingCommands class, 1093 Elapsed member, StopWatch class, 713 ElapsedMilliseconds property, StopWatch

class, 712 ElapsedTicks member, StopWatch class,

713 Element method, 942, 950, 955 elements

adding to XML, 950–952 changing and deleting, 955–956 filtering by name, 938–939 processing in arrays, 401–402

Elements( ) method, 938–940, 950 ellipsis (...) button, 1076 else clauses, 51 else if clauses, 51 else selection keyword, 75 Emd value, 655 Employee class, 268–269, 281, 284, 287, 975,

979, 994, 1055–1056 Employee copy constructor, 287 Employee database, 1060 Employee diagram, 999 Employee entity type, 994

Employee LastName field, 976 employee parameter, 242–243 Employee property, 981, 984–985 Employee records, 1118 Employee table, 997–998, 1053, 1117–1118 Employee1 property, 979 EmployeeDomainService.cs file, 1142–1143 EmployeeDomainService.metadata.cs file,

1143 EmployeeMetaData class, 1117–1118, 1121 Employees data, 1116, 1119 Employees entry, 1118 Employees field, 1058 Employees property, 975, 977, 980 Employees table, 975, 977, 979, 993, 995,

1014, 1018, 1086, 1110, 1117 Employees1 property, 979 Enable Editing option, 1143 Enabled property, 1059 enableOption parameter, 240 EnableRaisingEvents property, 647–648 enabling concurrency checking, 999 encapsulation, 159–160 EncapsulationTest class, 159–160 Encoding class, 706, 850, 1195 Encrypt( ) method, 632 encrypting data, 1189–1190 encryption keys, 1186–1188 Encrypt(string) method, 639 End method, 815, 818, 820, 823 EndGetHostEntry method, 818 EndInvoke method, 815, 820, 822 EndsWith(string) method, 499 Engine class, 176 EngineCapacity field, 145–146 EngineSpec class, 145 Enqueue method, 603–604 EnsureCapacity(int) method, 503 Ensures method, 1224 Entities menu, 991 Entity Data Model, 1109–1114 Entity Data Model Browser window, 990 Entity Data Model Wizard, 967 EntityCollection<Order> class, 980 EntityCollection<T> class, 980–981 EntityDataSource control, 1109, 1111 enum feature, 43 enum keyword, 65, 380 enum parameter, 313 enum values, 53, 520, 536

� INDEX

1246

enumerating arrays, 393–399

breaking from enumerations, 398–399

with a foreach loop, 395–396 jagged, 417–418 with a for loop, 393–395 rectangular, 412–413 using IEnumerator and

IEnumerator<T>, 396–398 directories, 622–627 results, 978 strings, 493

enums, 380–384 combining values, 383–384 defining, 380–381 underlying types and numeric values,

382–383 using, 381–382

Environment class, 850–852 Epsilon property, 107–108 EqualityComparer class, 609 Equals method, 48, 489, 608 equals sign (=) operator, 39, 46, 88 Equals(T, T) method, 608 Error List window, 1216 Error property, 684 ErrorWindow class, 1140 ErrorWindow.xaml item, 1138 escape sequences, string, 487–488 escaping braces, 510–511 event keyword, 317 event modifier, 71–72 event type, 71 Event value, 536 Event view, 1078 EventArgs class, 317–318, 323, 325, 646, 684,

1080 EventArgs pattern, 318 EventArgs.Empty property, 324 EventHandler delegate, 318, 322 EventHandler pattern events, defining and

publishing, 317–321 EventHandler type, 324 events, 315–325. See also wiring

applying modifiers to, 325 defining and publishing EventHandler

pattern events, 317–321 nongeneric, 322–323 specifying, 361

for WebClient class, for asynchronous requests, 682–684

without custom data, 323–324 Events view, 1078 EventStack<T> class, 468 ex class, 426 example code, downloading, 6 Except method, 1023–1024 Exception class, 429, 446, 448 exception handling keywords, 77–78 Exception property, 793, 795 exceptions, 419–451

casting objects without, 172–173 handling, 420–432

catch clauses, 421–426 catch clauses, general, 426 catch clauses, omitting, 426–427 exception members, 427–430 finally clauses, 430–432 try statements, 421–424 try statements, nesting, 427

in task body, 787–788 throwing, 432–451

aggregating exceptions, 446–451 creating and throwing custom

exceptions, 438–441 creating exception chains, 444–446 mapping exception types, 442–444 rethrowing exceptions, 436–438

from trigger method, 789–791 from multiple tasks, 790–791 using custom exception escalation

policy, 794–795 using properties, 792–794

Exception.ToString method, 428 ExceptWith(IEnumerable<T>) method, 595 ExcludeControlFromAeroGlass method,

1066 .exe file extension, 20 Executed event, 1093 ExecuteReader method, 1012 Exists method, 562 Exists property, 632, 635 Exists(string) method, 639 Exists(T[], PredicateT) property, 611 Exit method, 1048 Exit(int) method, Environment class, 850 ex.Message property, 426 Exp(double) method, Math class, 852 Expert Settings option, 9

� INDEX

1247

explicit casting exceptions, avoiding, 170–173

casting without exceptions, 172–173 testing object types, 170–172

vs. implicit casting, 165–169 explicit conversion modifier, 225 explicit keyword, 86, 226 explicitly implementing interfaces, 367–369 expressing

using literals, 482–483 using string literals, 486–488

expressions regular, 495 statements, 40

Extensible Markup Language. See XML extension methods, 301–304 Extension property, 632

� F F component, 513 F specifier, DateTime, 730 F suffix, 96 factory methods, 289–290 Factory property, 777 Factory.StartNew method, 779 Fail(string, string) method, 1209 Fail(string) method, 1209 FalseString field, 129 features, adding to classes, 133–136

constructors, 135–136 fields, 133–134 methods, 134–135

field iterators, exposing, 293–294 field types, mapping property typse to, 210 Field value, 536 Field<T> method, DataRowExtensions, 1016 field-backed properties, 204–207 fields, 183–201

adding to classes, 133–134 defining, 375 destruction stage, 193 initializing, 184–186 initializing at constructions, 274–275 modifiers of, 193–201

access modifiers, 199 hiding base class fields, 199–201 read-only fields, 196–198 static fields, 194–196 using volatile keyword, 201

reading and modifying, 140–142 reading and updating, 186–193

allowing classes to read and modify properties, 188–189

exposing properties with field values, 189–191

field values, 186–188 reference type fields, 191–193

static, 147–148 testing for attributes applied to, 525–527

FIFO (first-in, first-out), 554, 602 File class, 639–640, 642, 647, 653, 724, 1208 File menu, 11–12, 14 File MenuItem control, 1077 FileAccess enumeration, 661 FileAccess parameter, 634 FileAccess values, 661 File.Create method, 653–654 FileInfo class, 630, 634, 637, 724 FileMode enumeration, 660 FileMode parameter, 634 FileMode values, 660 FileName value, 650 files, 622–650

change monitoring, 645–650 filtering monitored files, 648–649 filtering triggers for change event,

649 FileInfo class, 631–634 getting and setting information for, 628–

629 spreading namespaces across, 344–345 System.IO.File class, 639–642

convenience methods, 640–642 reader methods, 642 stream, reader, and writer methods,

642 writer methods, 642

System.IO.Path class, 643–644 FileStream class, 634, 642, 653, 660–662, 666 FileSystemEventArgs class, 646 FileSystemInfo class, 637–638 FileSystemMonitor class, 648 FileSystemWatcher class, 645–649 FileSystemWatcher.NotifyFilter property,

649 Fill method, 1014–1015, 1018, 1020, 1022 Filter property, 648–649 FilterDescriptor constructor, 1149 FilterDescriptors property, 1148–1149

� INDEX

1248

filtering data

with LINQ, 874–876 with Windows Forms, 1060–1061

directories monitored, 648–649 results, 625–627 triggers for change events, 649

files monitored, 648–649 triggers for change events, 649

FilterOperator enumeration, 1149 FilterStack<U> method, 467 FinalCalculator class, 301 Finalize method, 542–543 finalizers, destructors versus, 542–543 finally clauses, 256, 426, 430–432 finally exception handling keyword, 78 Find method, 406–407, 563, 580 FindAll method, 407–408, 563–564, 610 FindAll(Predicate<T>) method, 560 FindAll(T[], Pridcate<T>) method, 611 FindIndex method, 563 FindIndex(int, int, Predicate<T>) method,

560 FindIndex(int, Predicate<T>) method, 560 FindIndex(T[], Predicate<T>) method, 611 finding list items

LinkedList<T> collection class, 580–581 List<T> collection class, 559–565

FindLast method, 563 FindLastIndex method, 563 FindLastIndex(int, int, Predicate<T>)

method, 560 FindLastIndex(int, Predicate<T>) method,

560 FindLastIndex(Predicate<T>) method, 560 FindLastIndex(T[], Predicate<T>) method,

611 FindLast(Predicate<T>) method, 560 FindLast(T) method, 580 FindLast(T[], Predicate<T>) method, 611 Find(Predicate<T>), 560 Find(T) method, 580 Find(T[], Predicate<T>) method, 611 First method, 980–981 First property, 577, 580 FirstChar property, 878 first-in, first-out (FIFO), 554, 602 FirstName column, 1016, 1120, 1146 FirstName field, 1018, 1026

FirstName property, 978 Flags attribute, 383, 520–521, 533 float keyword, 63, 93 float type, 93, 96, 98–99, 107, 977 float values, 43, 107–108, 111, 260, 512 float variable, 96 floating-point number, 93 Floor (decimal) method, 108 Floor(double) method, Math class, 852 Flush( ) method, 651, 655–656, 664 Flush(bool) method, 661 focus

managing, 1081–1082 setting, 1107–1108

Focus method, 1081 Font dialog box, 1041 Font property, 1041, 1106 Font settings, 1106 for Iterator keyword, 76 for keyword, 393 for loops, 56, 292, 393, 395, 413, 492, 706,

771, 788, 804 for statements, 393 ForAll method, 922, 960, 962 forcing parallel execution, 921–922 foreach Iterator keyword, 76 foreach keyword, 395 foreach loop, 292, 295, 396, 402, 556, 579,

681, 867, 937, 978 ForEach method, 401–402, 571–572 foreach statement, 393, 395 ForEach(Action<T>) method, 571 ForegroundColor property, Console class,

847 foreign key relationships, navigating using,

979–985 querying using navigation properties,

982 using navigation data, 983–985

Form1 class, 1035 Form1 constructor, 1046 Form1.cs file, 1046–1048, 1058, 1064 Form1.Designer.cs file, 1037, 1043, 1048 Format method, 517 formatProvider parameter, 517 Format(string, object) method, 496 formatString variable, 507 FormatterAssemblyStyle enumeration, 750 formatting

DataGrid controls, 1084–1085 DateTime strings, 730–733

� INDEX

1249

strings, 507–518 composite formatting, 507–511 creating string representations of

custom types, 514–516 formatting types, 511–514 performing custom composite

formatting, 516 TimeSpan strings, 720–723

Forms, Windows. See Windows Forms fragment.xml file, 936 Frequency member, StopWatch class, 713 from keyword, 865, 891 From property, 1088 FromAsync method, 824 FromDays(double) method, TimeSpan, 718 FromHours(double) method, TimeSpan,

718 FromMilliseconds(double) method,

TimeSpan, 718 FromMinutes(double) method, TimeSpan,

718 FromSeconds(double) method, TimeSpan,

718 FromTicks(double) method, TimeSpan, 718 FromXXX methods, 718 fuelRequired variable, 149 FuelType field, 145 FullName property, 637 FullPath property, 632, 646 fully qualified names, 338–349 Func class, 326 Func delegates, 328–332 Func parameter, 907 Func<int, int, int> type, 332 Func<int> type, 328 Funcs event, 64 Function Import Name text box, 991 Function Imports section, 991

� G G specifier, DateTime, 730 GC (garbage collector), 539–547

destructors, 541–543 finalizers versus, 542–543 problems with, 543

disposal, 544–545 running explicitly, 540 weak references, 546

general catch clauses, 426

generating hash codes, 1194–1196 generic types, 454–478

casting from parameterized types, 461–462

constraining parameterized types, 462–465

applying multiple constrains to parameterized types, 464

constraining multiple parameterized types, 465

creating generic interfaces, 471 generic structs, 472 objects from generic classes, 456–457

deriving from generic base class, 467–471

inheriting type deferral, 467–468 specifying parameterized types, 470–

471 generic class, 456 implementing and using generic class

members, 457–460 method-specific parameterized types,

465–467 multiple parameter types, 460–461 type variance, 472–477

combining contravariance and covariance, 477

contravariance, 476–477 covariance, 475–476

using default keyword, 477–478 GenericParameter value, 536 GenericStack constructor, 460 GenericStack<Car> class, 473–474, 477 GenericStack<int> class, 457–458, 470 GenericStack<string>, 457 GenericStack<T> class, 456–459, 462–464,

468, 475–476 GenericStack<VolvoC30> class, 473–474,

476 get accessor, 208–209, 211–212, 215–216,

218 Get Column Information button, 991 get keyword, 207–208, 213 get request, 217 get value keyword, 85 GetAllNetworkInterfaces method,

NetworkInterface class, 858–859 GetBaseException( ) method, 428, 446 GetBytes method, 850, 1198 GetClassAttribute method, 524

� INDEX

1250

GetCommandLineArgs( ) method, Environment class, 850

GetContext method, 702 GetCreationTime(string) method, 628, 639 GetCurrentDirectory( ) method, 629 GetDelegate method, 313 GetDirectories( ) method, 622–623, 627, 636 GetDirectories(string, SearchOption)

method, 636 GetDirectories(string, string) method, 622 GetDirectories(string, string, SearchOption)

method, 622 GetDirectories(string) method, 622, 636 GetDirectoryName(string) method, 643 GetEmployees method, 1144 GetEnumerator( ) method, 291, 294, 396–

397, 553, 867–868 GetEnvironmentVariables( ) method,

Environment class, 850 GetFileName(string) method, 643 GetFileNameWithoutExtension(string)

method, 643 GetFiles( ) method, 627, 637 GetFiles(string, SearchOption) method, 637 GetFiles(string, string) method, 622 GetFiles(string, string, SearchOption)

method, 622 GetFiles(string) method, 622, 637 GetFileSystemEntries method, 627 GetFileSystemEntries(string, string)

method, 623 GetFileSystemEntries(string, string,

SearchOption) method, 623 GetFileSystemEntries(string) method, 623 GetFileSystemInfos( ) method, 637 GetFileSystemInfos(string, SearchOption)

method, 637 GetFileSystemInfos(string) method, 637 GetFocus method, 1082 GetFormat method, 517 GetFullPath(string) method, 643 GetHashCode method, 608 GetHostEntry method, 708 GetHostEntryCallback method, 818 GetHostEntry(string) method, 708 GetHostName( ) method, 708 GetInvalidFileNameChars( ) method, 643 GetInvalidPathNameChars( ) method, 643 GetIsNetworkAvailable method,

NetworkInterface class, 858

GetLastAccessTime(string) method, 628, 639

GetLastWriteTime(string) method, 628, 639 GetLength method, 413 GetModifiedMethodNames method, 531 GetModifiedMethods method, 531 GetModifiedProperties method, 529 GetNonZeroBytes method, 1198 GetNumericValue(char) method, 485 GetOrder method, 1144 GetPathRoot(string) method, 643 GetRandomeFileName( ) method, 643 GetRange(int, int) method, 557 GetStream method, 687, 690 GetString method, 850 GetStringLength method, 433 GetTempFileName( ) method, 643 GetTempPath( ) method, 643 GetTimestamp( ) method, StopWatch class,

713 GetTimestamp method, 714 GetTotalValueOfStock method, 205 GetType( ) method, 94, 756, 762 GetViewBetween method, 602 GetViewBetween(T, T) method, 601 GetXXX method, 1144 GlassForm class, 1064 global keyword, 85, 87, 352–353 global namespace, 340 global:: prefix, 352 Global.asax.cs file, 1114, 1120–1121 GlobalSupressions.cs file, 1219 goes to operator, 335 GotFocus event, 1082 goto case statement, 52–53 goto jump keyword, 77 GreatestValue<T> method, 466 Grid columns, for Swimming Calculator

example, 1128–1130 Grid control, 1073, 1128–1130, 1133, 1135,

1144 Grid layout, 1073 Grid.Column property, 1131 Grid.ColumnSpan property, 1130, 1134 GridView control, adding, 1111–1112 group clause, 885–887, 890, 959–960 group key, 889 group keyword, 886, 893 group range variable, 890 GroupBy method, 893

� INDEX

1251

grouping data, with LINQ, 885–887 querying of grouped data, 890–891 using anonymous type, 889–890 using Boolean value, 887–888

.gzip extension, 666 GZipStream class, 664–666

� H H format component

DateTime, 732 TimeSpan, 722

Handle method, 448, 450 HandleClientStream method, 687 HandleEvent class, 321 HandleServerStream method, 690–691 handling exceptions, 420–432

catch clauses, 421–426 general, 426 omitting, 426–427

exception members, 427–430 finally clauses, 430–432 try statements, 421–424, 427

HasExtension(string) method, 643 hash codes, 1193–1197

generating, 1194–1196 verifying, 1196–1197

HashAlgorithm class, 1193 HashSet<string> class, 599 HashSet<T>( ) method, 598 HashSet<T> collection class, 597–599 HashSet<T>(IEnumerable<T>) method, 598 HashSet<T>(IEqualityComparer<T>)

method, 598 Hashtable class, 619 HasValue property, Nullable<T> struct, 841 Headers property, 677–678, 703, 1077, 1092 Height attribute, 1072 Height property

Button control, 1134 Label control, 1133 TextBlock control, 1134

HH format component, DateTime, 732 hiding methods, 263–264 HorizontalAlignment property, 1130, 1134 HorizontalContentAlignment property,

Label control, 1133 HostName property, 709, 824 hostNames array, 816 Hours property

DateTime, 726 TimeSpan, 716

HttpGetEnabled property, 696 HttpListener class, 700–704 HttpListenerContext class, 702 HttpListenerRequest class, 702 HttpListenerResponse class, 703 HttpListenerResponse.OutputStream

property, 703 HttpListenerResponse.StatusCode property,

703 HttpMethod property, 703

� I i < 3 condition, 394 i variable, 54–55, 394 IAsyncResult parameter, 818 IAsyncResult.AsyncState property, 818 IAsyncResult.WaitHandle method, 821 IBaseCalculator interface, 363 IBasicCalculator interface, 356–357 IBasicCalculator variable, 358 ICalculator interface, 366, 370–371 ICalculatorServer interface, 696 ICalculatorService interface, 698 ICollection<KeyValuePair<string, string>>

interface, 588 ICollection<KeyValuePair<TKey, TVal>>

interface, 588 ICollection<string> interface, 588 ICollection<T> interface, 553–555, 557, 576,

588–589, 609, 614 ICollection<TKey> interface, 586, 591 ICollection<TVal> interface, 586, 588, 591 ICombinedCalculator interface, 364 IComparable<T> interface, 463–466 IComparer<int> interface, 607 IComparer<string> interface, 569–570, 607–

608 IComparer<T> interface, 561, 568, 582, 594,

600–601, 603, 606–608, 611 IComparer<TKey> interface, 581–582, 594–

595 Icon property, 1082 icons

setting, 1082–1083 for Windows Forms program, 1053

ICryptoTransform interface, 1190 ICustomFormatter class, 517

� INDEX

1252

ID property, 1105–1106 id type, 976 identifiers, 34–36 IDerivedCalculator interface, 363 IDictionary interface, 428, 437–438 IDictionary<TKey, TVal> interface, 581,

586–588, 590–591, 595 IDisposable Interface, 544 IEnumerable, populating XElement or

XDocument with, 933–934 IEnumerable<char> interface, 493 IEnumerable<Employee> interface, 977, 986 IEnumerable<Exception> interface, 447 IEnumerable<string> interface, 496, 640–

641 IEnumerable<T> interface, 56, 556, 576, 600,

604, 610, 866, 868, 934, 977 IEnumerable<XAttribute> interface, 938 IEnumerable<XElement> interface, 937–

938, 947, 950, 960 IEnumerator interface, 396–398 IEnumerator<T> interface, 291, 294, 396–

398, 553, 601, 867 IEqualityComparer<string> interface, 609 IEqualityComparer<T> interface, 593, 597–

598, 603, 608–609 IEqualityComparer<TKey> interface, 590 if selection keyword, 75 if statements, 48–49, 55, 75, 116, 431 IFormatProvider interface, 516–518 IFormatter interface, 738–739, 754 Ignore button, 1230 IGrouping<TKey, TValue> interface, 886 IIS (Internet Information Services), 28 IList<string> class, 556, 614 IList<string> interface, 583 IList<T> interface, 294, 409, 554–557, 564,

609, 614 IllegalCall method, 65 images directory, 701 implementing interfaces, 365–374

explicitly, 367–369 implementing abstract classes, 370–371 inheriting implementations, 369–370 multiple interfaces, 366–367 overview, 357–358

implicit casting, vs. explicit casting, 165–169 implicit conversion modifier, 225 implicit keyword, 86 importing namespaces, 339–340 in, out modifier, 72

in keyword, 395, 475–476, 865, 891 Include method, 984–985 IncludeSubdirectories property, 648 increment operator (+=), 72, 88–89 IncrementCounter method, 810, 813 Indent( ) method, 1209–1210 indenting Debug output, 1211–1212 index parameter, 215, 433 indexers, 215–219

multiple, 216–217 with multiple arguments, 218–219 specifying, 362 StringBuilder, 506 validating, 217–218

IndexOf method, 556, 564–565 IndexOfAny(char[]) method, 499 IndexOf(char) method, 499 IndexOfKey property, 582–583 IndexOfKey(TKey) property, 582 IndexOfOufRangeException class, 434 IndexOf(string) method, 499 IndexOf(T) method, 555 IndexOfValue property, 582–583 IndexOutOfRange exception, 444 inheritance, 153–158

and base structs, 375 controlling in custom attributes, 537 inheriting derivations, 157–158 overriding methods, 156–157

Inherited property, 537–538 inheriting

implementations, 369–370 type deferral, 467–468

initialization vector, 1188 InitializeComponent method, 1046 initializers

of arrays, 391–392 of jagged arrays, 417 of rectangular arrays, 411–412

initializing arrays, 387–389 inner classes, 175 InnerException property, 428, 446 InnerExceptions collection, 790 InnerExceptions property, 448, 790 InputStream property, 703 Insert methods, 503, 505–506, 556–557 InsertAt(int, char) method, SecureString

class, 1199 inserting data, databases operations with

LINQ, 1024–1026 Insert(int, string) method, 496, 503

� INDEX

1253

Insert(int, T) method, 555 InsertRange(int, IEnumerable<string>)

method, 557 Installed Templates section, 11 InstallState enumeration, 1155 instance field, 194 instance methods, 257 instantiating structs, 371–374 int arguments, 219 int array, 388 int data type, 957 int keyword, 68, 92–93, 103 int parameters, 160, 250, 260–261, 307, 328,

357, 446, 502, 1202 int range variable, 945 int result, 160, 224, 331 int type, 43, 94, 99, 111, 117, 134, 145, 184,

224, 240 int values, 43, 46, 111–112, 249, 269, 307,

455, 471, 654 int variable, 46–47, 49, 143 integer index parameter, 217 integer type, 93, 108 integer values, 126–127 interface keyword, 65–66, 357 Interface value, 536 interfaces, 356–371

defining, 356–357 deriving, 362–365 generic, creating, 471 IEnumerator, 396–398 IEnumerator<T>, 396–398 implementing, 365–374

explicitly, 367–369 implementing abstract classes, 370–

371 inheriting implementations, 369–370 multiple interfaces, 366–367 overview, 357–358

IQueryable<T>, 977–978 partial interfaces, 365 specifying

events, 361 indexers, 362 methods, 359 properties, 359–360

using, 358 internal access modifier, 70, 181, 199, 211,

283 internal keyword, 302, 325 internal modifier, 69–70, 234

Internet Information Services (IIS), 28 Internet Protocol (IP), 675, 704 interrogating delegates, 313–315 Intersect method, 1021–1022 Interset operator, 1024 IntersetWith(IEnumerable<T>) method, 595 into keyword, 890–891 int.Parse method, 105, 277 IntStack class, 454, 470–471 invariant contracts, 1225–1226 InvariantContracts method, 1226 IO, 621–673

directories, 622–650 change monitoring, 645–650 changing current working, 629–630 DirectoryInfo class, 630–638 getting and setting information for,

628–629 System.IO.Directory class, 622–630 System.IO.Path class, 643–644

files, 622–650 change monitoring, 645–650 FileInfo class, 631–634 getting and setting information for,

628–629 System.IO.File class, 639–642 System.IO.Path class, 643–644

readers, 666–673 reading binary data, 667–669 reading textual data, 670–673

streams, 650–666 base, 657–662 pass-through, 663–666 System.IO.Stream class, 653–657

writers, 666–673 writing binary data, 667–669 writing textual data, 670–673

IP (Internet Protocol), 675, 704 IPAddress class, 690 IPAddress.Any property, 686 IPHost entry, 818 IPHostEntry class, 708 IPop<Car> interface, 476 IPop<T> interface, 475 IProductCalculator interface, 364, 367–368 IPush<VolvoC30> interface, 477 IQueryable<T> interface, 977–978 is object keyword, 83 is operator, 172 Is64BitOperatingSystem property,

Environment class, 851

� INDEX

1254

Is64BitProcess property, Environment class, 851

IsAvailable property,, 860 IsCanceled property, 782 IsCancellationRequested property, 783–

784 IsChecked property, 1094–1095 IsCompleted property, 782 IsDigit(char) method, 485 IsEnabled property, 1155 ISet<T> interface, 595–597, 599 IsFaulted property, 782, 793 IsHighResolution member, StopWatch

class, 713 IsInfinity(V) method, 107 IsLetter(char) method, 485 IsLetterOrDigit(char) method, 485 IsLocal property, 703 IsLower(char) method, 485 IsNegativeInfinity(V) method, 107 IsOver18 property, 279 IsPositiveInfinity(V) method, 107 IsProperSubsetOf(IEnumerable<T>)

method, 595 IsProperSupersetOf(IEnumerable<T>)

property, 595 IsPunctuation(char) method, 485 IsReadOnly property, 553, 614, 632 IsRunning member, StopWatch class, 713 IsRunningOutOfBrowser property, 1155 IsSeparator(char) method, 485 IsSubsetOf(IEnumerable<T>) property, 595 IsSupersetOf(IEnumerable<T>) property,

596 IsSymbol(char) method, 485 IsTabStop property, 1077–1078 IStack<T> interface, 471 ISubtractionCalculator interface, 364 ISumCalculator interface, 364, 367–368 IsUpper(char) method, 485 IsWhiteSpace(char) method, 485 Item indexer, 555, 586, 591 Item property, 582 items

finding in arrays, 406–408 Menu, 1077 StatusBar, 1076–1077

Items property, 1076–1077, 1092 ItemsInStock element, 960

itemsInStock field, 184–186, 188–189, 191, 206–208

ItemsInStock property, 191, 205–206, 208–209, 211, 220, 223, 912, 929

ItemsInStock value, 223 iterating data items, 53–60

using a do...while loop, 58 using a for each loop, 56–57 using a for loop, 53–56 using a while loop, 59–60

iteration statements, 40 Iterative value, 313 iterator blocks, 291–296

exposing field iterators, 293–294 multiple yield statements, 294–295 named, 295–296 yield keyword, 292–293

Iterator keywords, 75–76 IV property, 1188

� J j variable, 55 jagged arrays, 415–418

enumerating, 417–418 getting and setting values, 416–417 initializers, 417

JavaScript Object Notation (JSON), generating with Data Contract Serializer, 763–764

JIT (Just-In-Time) Compiler, 23 join keyword, 909 Join method, 908–910 join query keyword, 908 joins, performing on DataSets, 1018–1024 Join(string, IEnumerable<string>) method,

496 Jones, Allen, 28, 1185 JSON (JavaScript Object Notation),

generating with Data Contract Serializer, 763–764

jump keywords, 76–77 Just-In-Time (JIT) Compiler, 23

� K Key property, 588, 886, 1080, 1187–1188 KeyCode property, 1049 KeyDown events, 1048–1049, 1080

� INDEX

1255

KeyEventArgs class, 1080 Keys enum, 1049 Keys property, 582–583, 586, 588, 591 KeyStack class, 461 KeyValuePair structure, 588 KeyValuePair<string, string> class, 588 KeyValuePair<TKey, TVal> structure, 588–

589 keywords, 84–87

arithmetic overflow, 78 base, 84–85 const, 196–197 default, 477–478 exception handling, 77–78 get, set, value, 85 global, 85 implicit, explicit, 86 Iterator, 75–76 jump, 76–77 LINQ, 84 literal, 82–83 namespace, 81–82 object, 83–84 operator, 86 overview, 37 parameter, 79–81

out, 81 params, 79–80 ref, 80

partial, 86 readonly, 197–198 selection, 75 synchronization, 79 this, 86 type, 61–69

bool, 62 byte, sbyte, 62 char, 62 class, 63 decimal, double, float, 63 delegate, 64 dynamic, 64–65 enum, 65 interface, 65–66 object, 66–67 short, ushort, int, uint, long, ulong,

68 string, 67 struct, 67–68 var, 69 void, 68

using, 86 volatile, 196–201 yield, 86–87, 292–293

Klein, Scott, 29

� L L suffix, 95–96 Label, Windows Forms example program

with, 1038 Label controls

configuring, 1074 for Swimming Calculator example,

1132–1133 labels, 1104 lambda expressions, 334–336 Language Integrated Query. See LINQ language syntax, 33–46

C# syntax, 34–41 comments, 40–41 identifiers, 34–36 keywords, 37 literals, 37 operators, 38–39 punctuators, 39–40 statements, 40

types, 41–46 definite assignment and null

references, 45–46 reference, 43–45 value, 42–43

lapsTextBox control, 1078, 1106 Last property, 577 LastAccess value, 650 LastAccessTime property, 632, 635, 637 last-in, first-out (LIFO), 604 LastIndexOf method, finding list items with,

564–565 LastIndexOfAny(char[]) method, 499 LastIndexOf(char) method, 499 LastIndexOf(string) method, 499 LastIndexOf(T, int, int) method, 560 LastIndexOf(T, int) method, 560 LastIndexOf(T) method, 560 LastName field, 1000, 1016, 1018, 1026,

1120, 1146 LastName property, 975–976, 978, 999 lastResult field, 1226 LastWrite value, 650 LastWriteTime property, 632, 635, 637

� INDEX

1256

Layout group, 1084 left-shift operator, 119 legacy collections

as data source for LINQ, 902–904 range variable type, 902 using Cast method, 903 using OfType method, 904

overview, 617–619 Length member, 877 Length property, 394–395, 492, 501, 632,

652, 878, 885 lengthTextBox control, 1078 Lerman, Julia, 29 Leroux Bustamante, Michele, 29 let keyword, 911–912, 945 lifetimes, of variables, 255–256 LIFO (last-in, first-out), 604 Lines property, 1053 LinkedList<T>( ) method, 576 LinkedList<T> collection class, 575–581

adding list items, 576–580 finding list items, 580–581 removing list items, 576–580 retrieving list items, 576–580

LinkedList<T>(IEnumerable<T>) method, 576

LinkedListNode<T> class, 576–577, 580 LinkedListNode<T> property, 576 LinkedListNodes<T> class, 579 LINQ (Language Integrated Query)

data binding with Windows Forms, filtering data, 1060–1061

keywords, 84 overview, 26–27 using arrays with, 408

LINQ to DataSet class, 1001–1030 connecting to database, 1004–1008 database operations with, 1024–1030 DataSet class overview, 1012–1014 enumerating results, 1014–1016 executing query, 1010–1012 querying DataSets, 1016–1030

for data intersects, 1021–1022 performing joins on, 1018–1024 subtracting results, 1023–1024

setting up database, 1002–1004 storing connection strings, 1008–1010

LINQ to Entities, 965–1000 creating models, 967–973 deleting data, 998–999 enabling concurrency checking, 999

enumerating results, 978 inserting data into databases, 993–996 navigating using foreign key

relationships, 979–985 querying using navigation

properties, 982 using navigation data, 983–985

preparing databases, 967 querying data, 985–993

compiling queries, 985–988 querying stored procedures, 989–993 querying views, 988–989

understanding IQueryable<T> interface, 977–978

updating data in databases, 996–997 using data model context, 974 using table properties and row objects,

975–976 LINQ to objects, 863–913

aggregating data, 905–910 converting results, 899–901 creating additional range variables, 911–

913 creating combinations of data, 910–911 data sources for, 866–867 deferred execution of, 895–899

forcing immediate execution, 897–899

referring to variables, 896–897 reusing queries, 895–896

filtering data, 874–876 grouping data, 885–887

querying of grouped data, 890–891 using anonymous type, 889–890 using Boolean value, 887–888

legacy collections as data sources, 902–904

range variable type, 902 using Cast method, 903 using OfType method, 904

method syntax for, 891–894 ordering data, 881–885 projecting data, 876–881

anonymous types, 877–879 derived data, 879–881 single member, 876–877

query types, 870–874 compiler-inferred types, 873–874 range variable type, 870–873 result type, 870–872

and results, 867–869

� INDEX

1257

enumerating manually, 867–868 using as data sources, 868–869

LINQ to XML, 925–963 classes, 926–944

creating other XML node types, 930–931

creating valid XML documents, 932–933

creating XElements using arbitrary types, 928–930

modifying XML, 940–944 populating XElement or XDocument

with IEnumerable, 933–934 processing XML declaratively, 936–

940 reading and writing XML files, 934–

936 queries, 944–963

create objects from XML, 949–950 creating XML from LINQ queries,

946–949 grouping XML, 958–960 modifying and transforming XML

data, 950–956 querying XML for data, 945 sorting XML, 957–958 using Parallel LINQ (PLINQ) to

process XML, 960 List property, 576 List<<T> class, 564 List<Exception> class, 446–447 List<int> class, 573 List<object> class, 618 List<string> class, 556, 562, 573, 599, 610 List<T>( ) method, 557 List<T> capacity property, 573 List<T> collection class, 556–575

adding list items, 557–559 finding list items, 559–565

with LastIndexOf method, 564–565 using binary searches, 560–561 using predicates, 561–564

processing list items, 571–572 removing list items, 557–559 retrieving list items, 557–559 sorting list items, 565–570

List<T> interface, 576 List<T> methods, 561 List<T>(IEnumerable<T>) method, 557 List<T>(int) method, 557 List<TOut> class, 572–573

listeners, Debug, 1207–1209 lists, 554–585

IList<T> interface, 555–556 LinkedList<T> collection class, 575–581

adding items, 576–580 finding items, 580–581 removing items, 576–580 retrieving items, 576–580

List<T> collection class, 556–575 adding items, 557–559 finding items, 559–565 processing items, 571–572 removing items, 557–559 retrieving items, 557–559 sorting items, 565–570

read-only, 613–614 SortedList<TKey, TVal> collection class,

581–585 adding items, 582–585 removing items, 582–585 retrieving items, 582–585

literal keywords, 82–83 literal prefixes, 96–97 literal suffixes, 95–96 literals

Boolean, 127–128 overview, 37

Load method, 936 Loaded event, 1081, 1085, 1092 Loaded method, 1155 loading data, 1085 local variables, 251–256

naming variables, 253–254 variable scopes and lifetimes, 255–256

lock keyword, 201, 807 lock statement, 807–808 lock synchronization keyword, 79 Lock(long, long) method, 661 Log10(double) method, Math class, 852 Log(double) method, Math class, 852 logical AND operator, 119 logical NOT operator, 119 logical operators, 118–122 logical OR operator, 119 logical XOR operator, 119 long keyword, 68, 92 long type, 93–94, 96, 98–99, 113, 117, 126,

388, 976 long values, 43, 632, 655, 669 LongCount( ) method,

System.Linq.Enumerable class, 905

� INDEX

1258

LongLength property, 402 Loopback property, 690 loops

do...while loops, 58 for each loops, 56–57 for loops, 53–56 parallel, 824–831

breaking and stopping, 827–831 creating, 826–827

while loops, 59–60 lowStock variable, 912

� M M format component

DateTime, 732 TimeSpan, 722

m format component, DateTime, 732 M specifier, DateTime, 730 M suffix, 95–96 MacDonald, Matt, 26, 28 MachineName property, Environment

class, 851 Main method, 15–16, 269–271, 284, 423, 448,

774, 1034 MainPage.xaml file, 1127, 1139, 1144 MainWindow constructor, 1097 MainWindow.xaml.cs file, 1079 ManageCalculator method, 254 manipulating strings, 496–499 mapping exception types, 442–444 Margin property

Button control, 1134 Label control, 1133 TextBlock control, 1134

Math class, 852–853 Max( ) method, System.Linq.Enumerable

class, 905 Maximum property, 1040 Max(int, int) method, Math class, 852 MaxValue property, 103–104 maxValues[i] parameter, 779 md parameter, 240 MD5 class, 1193 MD5Cng class, 1193 MD5CryptoServiceProvider class, 1193 MediaCommands class, 1093 members

of classes, 496–501 manipulating strings, 496–499

other class members, 500–501 searching strings, 499–500

exception, 427–430 generic class, 457–460 struct, 103–109

getting range of supported values, 104

Parsing numeric values, 105–106 type-specific members, 107–109 using, 129–130

MemoryBuffer class, 658 MemoryStream( ) method, 658 MemoryStream class, 657–659, 667, 1189 MemoryStream(byte[]) method, 658 MemoryStream(int) method, 658 Menu control, 1077–1078, 1090, 1092, 1136 Menu items, adding, 1077 MenuItem control, 1077–1078, 1092, 1097 MenuStrip, Windows Forms example

program with, 1041–1042 Message property, 270, 424, 426, 428 message variable, 333 MessageBox.Show method, 1093 MetaData.cs file, 1117 MetadataType attribute, 1118 Method property, 314–315 method syntax, for LINQ, 891–894 Method value, 536 MethodAttributePair<T> struct values, 531 MethodOne method, 423–424 methods, 229–304

abstract, 299–301 adding to classes, 134–135 anonymous, 329–333 Append and Insert, 505–506 asynchronous, 816–824

mixing with tasks, 823–824 overview, 819–820 waiting to complete, 820–823

bodies of, 251–257 defining, 237–238 local variables, 251–256 using method results, 256–257

Console.WriteLine and Console.ReadLine, 16

constructors, 272–290 access to, 283 calling base class constructors, 280–

283 controlling access to constructors,

284

� INDEX

1259

copy, 284–287 factory methods, 289–290 initializing properties and fields at

constructions, 274–275 optional parameters in, 279–280 overloading, 275–280 static, 287–289 using, 274

destructors, 290 extension, 301–304 hiding, 263–264 iterator blocks, 291–296

exposing field iterators, 293–294 multiple yield statements, 294–295 named, 295–296 yield keyword, 292–293

Main method, 15–16, 269–271 modifiers of, 257–259

abstract, 259 access, 257 defining, 234–237 sealed, 258–259 static, 257–258 virtual, 258

names, 232 overloading, 259–261 overriding, 156–157, 265–267 parameters, 233–251

arrays of, 247–249 named, 250–251 optional, 249–250 output, 245–247 reference, 243–245 value, 239–243

partial, 296–299 result types, 232–233 sealing, 267–268 specialization of, 268–269 specific parameterized types, 465–467 specifying, 359 testing for attributes applied to, 530–532 using, 238–239 for WebClient class, 679–681

MethodThree method, 423–424 MethodTwo method, 423–424 Microsoft SQL Server Database File option,

969 Microsoft.Performance group, 1216, 1220 Microsoft.WindowsAPICodePack.dll file,

1063

Microsoft.WindowsAPICodePack.Shell namespace, 1064

Microsoft.WindowsAPICodePack.Shell.dll file, 1063

Milliseconds property DateTime, 725 TimeSpan, 716

Min( ) method, System.Linq.Enumerable class, 905

Minimum property, 1040 Min(int, int) method, Math class, 852 MinusOne property, 108 Minutes property

DateTime, 725 TimeSpan, 716

minutesTextBox control, 1078, 1106–1108 MinValue property, 103–104 mm format component, DateTime, 732 MM format component, DateTime, 732 MMM format component, DateTime, 733 MMMM format component, DateTime, 733 Model Browser window, 991 models, creating, 967–973 modifiers, 69–75, 176–181, 211–214

abstract, 71, 213 access, 180–181, 210–211 applying to events, 325 const, 71 creating

abstract classes, 178–179 partial classes, 179–180 sealed classes, 179 static classes, 176–177

event, 71–72 of fields, 193–201

access modifiers, 199 hiding base class fields, 199–201 read-only fields, 196–198 static fields, 194–196 using volatile keyword, 201

in, out, 72 of methods, 257–259

abstract, 259 access, 257 defining, 234–237 sealed, 258–259 static, 257–258 virtual, 258

override, 73 public, protected, private, internal, 69–

70

� INDEX

1260

modifiers (cont.) readonly, 73–74 sealed, 74 sealed keyword, 213 static, 74 static keyword, 214 using access modifiers, 180–181 virtual, 75 virtual and override, 212–213

Modulus operator, 109 Month property, DateTime, 726 MoveNext( ) method, 397, 867–868 Move(string, string) method, 639 MoveTo(string) method, 632, 635 mscorlib assembly, 553 MSDN C# programming guide, 6 multicasting, with delegates, 310–312 MultiLine property, 1038, 1053 multiple

parameter types, 460–461 results, returning using Tuple class, 836–

838 Multiplication operator, 109 MultiplierField field, 526–527 multi-threaded, vs. single-threaded, 768–

771 myChar variable, 482, 484 MyClass class, 232, 236, 238–239, 242, 343,

544–545 MyClass type, 341, 344 MyClass.MyMethod method, 240 MyConsolerHelper class, 346 MyData type, 240 myField field, 200 myField value, 201 myFile.txt file, 1208 MyFirstProject namespace, 15 MyFirstProject.exe file, 20 myInt variable, 42 myLocalVar variable, 431 MyMethod method, 242–243, 245 MyMethod parameters, 240 myName variable, 52 MyNamespace namespace, 340, 342–344 MyNamespace.MyClass class, 341, 343 MyNamespace.NestedNamespace

namespace, 344 MyNamespace.NestedNamespace.Addition

Helper class, 343 myObject reference, 44, 167 myObject variable, 168, 479, 867

myObject2 reference, 44 myperson variable, 243 MyProducts enum, 520 myString variable, 487

� N N component, 513 Name element, 951 name field, 753 name parameter, 277 Name property, 226, 242, 479, 635, 637, 758–

759, 937–938, 943 Name value, 223 nameArray variable, 389 Named Connection list, 1109 named iterator blocks, 295–296 named parameter, 250–251 nameLength variable, 912 names, of methods, 232 Namespace box, 698–699 namespaces, 337–353, 1117

consuming, 337–340 importing namespaces, 339–340 using fully qualified names, 338–339

creating, 340–346 adding types to existing namespaces,

346 logically nesting namespaces, 343–

344 nesting namespaces, 342–343 spreading namespaces across files,

344–345 disambiguating, 347–353

with aliases, 349–350 aliasing namespaces, 350–351 with fully qualified names, 349 resolving type or namespace hiding,

351–353 keywords, 15, 81–82, 341 statements, 15

naming variables, 253–254 NaN property, 107 navigating using foreign key relationships,

979–985 querying using navigation properties,

982 using navigation data, 983–985

NavigationCommands class, 1093 nchar type, 976

� INDEX

1261

NefariousClass constructor, 316, 321 NefariousClass method, 317 Negate(decimal) method, 108 NegativeInfinity property, 107 nested classes, 175–176 NestedNamespace namespace, 343 NestedNamespace.AdditionHelper class,

343 nesting

namespaces, 342–344 try statements, 427

.NET Class Library, 21

.NET Framework, 18–29 automatic memory management, 23 Class Library, 18 Common Language Runtime (CLR), 18 Cross-Platform Support, 29 Just-In-Time Compiler (JIT), 23 .NET technology Spectrum, 24–29

ADO.NET, 28–29 ASP.NET, 26 LINQ, 26–27 Task Parallel Library (TPL), 27 user interfaces, 27–28 Windows Communication

Foundation (WCF), 29 object-orientation, 22 parallel processing, 23–24 relationship with C#, 19–20 type safety, 22–23 Unmanaged/Native Code Support, 24

.NET tab, 753 NetDataContractSerializer class, 762–763 netsh command, 696 network connectivity, checking for, 857–860 NetworkAvailabilityChanged event,

NetworkChange class, 859 NetworkChange class, 859 networking, 675–709. See also parallel

programming Dns Class, 707 HttpListener class, 700–704 socket programming, 684–693

parallel server for, 691–693 TcpClient class for, 689–691 TcpListener class for, 685–688

UdpClient class, 704–707 with WCF, 693–700

client with, 697–700 server with, 694–696

WebClient class, 675–684

events for asynchronous requests, 682–684

methods for, 679–681 properties for, 677–678 ResponseHeaders property for, 680–

681 NetworkInterface class, 857–859 NetworkInterfaceType enumeration, 859 NetworkInterfaceType property,

NetworkInterface class, 859 new( ) constraint, 464 new access modifier, 381 New action, 1094 New command, 1092–1093, 1096 New Connection button, 968 New feature, 1092 New function, 1091 new keyword, 93, 176, 185, 199, 212, 252,

263, 273–274, 388 new modifier, 263 new object keyword, 83–84 new operation, 273, 1096 new operator, 136–138 New Project dialog box, 11 New Project menu option, 11 New Silverlight Application dialog box,

1127, 1141 NewRow method, 1026 Next( ) method, Random class, 849 Next property, 576, 580 NextBytes(byte[]) method, Random class,

849 NextDouble( ) method, Random class,

849 Next(int, int) method, Random class,

849 Next(int) method, Random class, 849 no name string, 218 node types, XML, 930–931 nongeneric events, 322–323 NonSerialized attribute, 744–746 NonSerialized field, 745 Normal enum value, 313 Northwind class, 975 Northwind data model, 989 Northwind database, 10, 974, 1053, 1086,

1099 Northwind Employees table, 1054 Northwind files, 10 Northwind model, 990 Northwind table, 1022

� INDEX

1262

Northwind_log.LDF file, 967, 1002 NorthwindEntities class, 974 NorthwindEntities field, 1085 Northwind.mdf file, 967, 970, 994, 1002–

1004 NorthwindModel project, 974 NorthwindModel.edmx entry, 988, 999 NorthwindModel.edmx model, 967, 975 NorthwindModel.Store entry, 988 NotifyCalculation delegate, 310 NotifyFilter property, 648–649 NotifyFilters enum, 649–650 NotImplementedException class, 434 NotInstalled state, 1155 NotSupportedException class, 434, 615 Now property, 724 ntext type, 976 null literal keyword, 82–83 null references, 45–46 null type, 106, 389, 395 null values, 45–46, 256, 396, 403, 407–408 nullable types, 841–843 Nullable<int> struct, 842 Nullable<T> struct, 841 Nullable<T>.HasValue property, 841 NullReferenceException class, 78, 420, 422,

424–425, 429, 431, 436–438 numeric operators, 109–125

arithmetic, 109–113 assignment, 122–125 logical, 118–122 relational, 116–118 unary, 113–116

numeric types, 92–109 implicit and explicit numeric type

conversions, 98–101 literal prefixes, 96–97 literal suffixes, 95–96 overflow checking, 101–103 struct members, 103–109

getting range of supported values, 104

Parsing numeric values, 105–106 type-specific members, 107–109

numeric values, underlying, 382–383 NumericUpDown controls, 1040, 1044–

1045, 1051–1052, 1072–1074, 1079 nvarchar type, 976

� O O alias, 351 object class, 167, 170, 455, 457, 461, 517,

523, 552, 618 object data source, data binding with

Windows Forms, 1054–1056 object initialization, 274 object keywords, 66–67, 83–84 object parameter, 446, 517, 526, 670 object type, 44, 391, 397, 1120 object-orientation, 22 object-relational mapping (ORM), 965 objects, 139–150, 165–175

avoiding explicit cast exceptions, 170–173

casting without exceptions, 172–173 testing object types, 170–172

boxing and unboxing, 173–175 calling methods, 148–150 create from XML, 949–950 creating, 136–139 creating from generic classes, 456–457 implicit vs. explicit casting, 165–169 reading and modifying fields, 140–142 references to common objects, 142–146 type conversion exceptions, 169–170 using static fields, 147–148

ObjectSet<Employee> collection, 975 ObjectSet<T> class, 975 ObjectSet<T> property, 993 Obsolete attribute, 522–523, 525–528 occurrences, suppressing, 1217–1220 OfType method, 904 OldFullPath property, 646 omitting catch clauses, 426–427 OnCalculationPerformed method, 318–319,

324–325 OnDeserialized attribute, 747 OnDeserializing attribute, 746–747 One property, 108 OnlyRanToCompletion enum, 802 OnSerialized attribute, 747 OnSerializing attribute, 747 OnXXX method, 325 Open method, 696, 1006, 1012 Open value, 660 Open(FileMode, FileAccess) method, 634 Open(FileMode) method, 634

� INDEX

1263

OpenOrCreate value, 660 OpenRead( ) method, 634, 676, 679 OpenReadAsync(Uri) method, 683 OpenReadCompleted event, 683 OpenReadCompletedEventArgs class, 683–

684 OpenRead(string) method, 642, 679 Open(string, FileMode) method, 642 OpenText( ) method, 634 OpenWrite( ) method, 634 OpenWriteAsync(Uri) method, 683 OpenWriteCompleted event, 683 OpenWriteCompletedEventArgs class, 683–

684 OpenWrite(string) method, 642, 679 operands, 38 OperationalStatus enumeration, 859 OperationalStatus property,

NetworkInterface class, 859 OperationCanceledException exception,

784 OperationContract attribute, 694 operations, performing, 483–494

combining strings, 491–492 comparing strings, 489–490 enumerating strings, 493 reading individual characters, 492–493 using strings in switch statements, 494

operator keyword, 85–86, 220, 225 operators, 219–227

arithmetic, 109–113 assignment, 122–125 custom

binary, 221–224 conversion, 225–227 unary, 219–221

logical, 118–122 overview, 38–39 relational, 116–118 unary, 113–116

OptimisticConcurrencyException, 1000 optional parameters, 249–250, 279–280 OptionalField attribute, 751–752, 754 Options dialog box, 1103 OR (||) operator, 88, 875 orange.jpg file, 704 Order class, 348, 980 order clause, 891 orderby clause, 881–885 orderby keyword, 893 OrderBy method, 893

ordering data, with LINQ, 881–885 Orders column, 1116 Orders property, 980 Orders table, 979–980, 1118, 1121, 1142 OrderSystem namespace, 348 OrderSystem.Order, 348 OrderSystem.Product class, 347–348 OriginalPath property, 632 ORM (object-relational mapping), 965 OSVersion property, Environment class, 851 Other Windows submenu, 12 OtherField field, 527 out keyword, 81, 247, 475–476, 836–837 out parameters, 81, 103, 129, 461, 584–585,

813 out TVal parameter, 586, 590 outer class, 176 outer variables, capturing, 331–333 Out-of-Browser Settings button, Visual

Studio, 1150 Out-of-Browser Settings dialog box, Visual

Studio, 1151 out-of-browser support, for Silverlight,

1149–1157 configuring, 1150–1151 features for, 1157 installation of, 1153–1156 using program out-of-browser, 1152–

1153 output parameter, 245–247 OutputStream property, 704 overflow checking, 101–103 Overlaps(IEnumerable<T>) property, 596 overloading methods, 232, 259–261, 280 override keyword, 74, 156, 163, 212, 267,

300, 358–359, 370, 375 override modifiers, 73, 75, 212–213, 266–267 overriding methods, 156–157, 265–267

� P P component, 513 PadLeft(int) method, 496 PadRight(int) method, 496 pagefile.sys file, 625 PaintColor enum, 381 PaintColor field, 134, 136–137 Panel control, 1065–1066, 1102 Parallel class, 826 parallel execution, forcing, 921–922

� INDEX

1264

Parallel LINQ. See PLINQ parallel loops, 824–831

breaking and stopping, 827–831 creating, 826–827

parallel processing, 23–24 parallel programming, 767–813

single-threaded, vs. multi-threaded, 768–771

Task class creating object, 772–773 exceptions from trigger method,

789–791 exceptions in task body, 787–788 getting details of antecedent, 797–

798 getting status of, 780–782 passing parameters to, 778–780 results from, 776–778 sharing data between tasks, 803–809 Start( ) method for, 773–774 Wait( ) method for, 774–776

using concurrent collections, 809–813 parallel server, for socket programming,

691–693 ParallelExecutionMode enumeration, 921 Parallel.For method, 815, 827 Parallel.ForEach method, 815, 827 Parallel.ForEach<T> method, 825 ParallelLoopState class, 815, 827 Parameter value, 536 parameterized types

casting from, 461–462 constraining, 462–465

applying multiple constrains to parameterized types, 464

constraining multiple parameterized types, 465

method-specific, 465–467 parameters

applying attributes with, 521–522 keywords, 79–81

out, 81 params, 79–80 ref, 80

of methods, 233–251 arrays of, 247–249 named, 250–251 optional, 249–250 output, 245–247 reference, 243–245 value, 239–243

passing to Task class, 778–780 types, multiple, 460–461

ParamName property, 434 params modifier, 247–248 params parameter keyword, 79–80 Parent property, 635 Parse method, 105, 834 Parse(string) method, 103, 129 Parsing numeric values, 105–106 partial classes, creating, 179–180 partial interfaces, 365 partial keyword, 86, 297, 365 partial methods, 296–299 Pascal case style, 35 pass-through streams, 663–666

buffered, 663–664 compressing data with, 664–666

Password property, ProcessStartInfo class, 1200

Path class, 642–644 PathSeparator method, 643 Peek( ) method, 603–605 perfCalc field, 307 PerformCalc delegate, 306–308, 820 PerformCalc field, 307 PerformCalculation method, 246–247, 254,

258, 299, 332, 369, 440–441, 838 PI method, Math class, 852 PLINQ (Parallel LINQ), 915–923

forcing parallel execution, 921–922 performing queries, 915–918 performing queries without results, 922–

923 result ordering, 918–921

polymorphism, 160–165 Pop( ) method, 454, 458, 461, 468, 473–475,

604–605 PopAndConvertMethod method, 478 Position property, 652 PositiveInfinity property, 107 postcondition contracts, 1223–1224 postfix decrement operator, 113 postfix increment operator, 113–114 Ppp interface, 859 precondition contracts, 1222–1223 Predicate class, 450 Predicate<string> class, 562 Predicate<T> class, 561, 601 PredicateExample method, 562 predicates, finding list items using, 561–564 prefix decrement operator, 113

� INDEX

1265

prefix increment operator, 113 prefixes, literal, 96–97 Press enter to finish message, 774 Previous property, 576, 580 pricePerItem field, 209 PricePerItem property, 209 PricePerItem value, 223 PRINT_CALC_DETAILS symbol, 854, 857 printArrayContents method, 395 PrintInformation method, 268, 302 printItem method, 401 PrintMessage method, 263 PrintOutCalculationDetails method, 854–

855, 857 PrintTripDetails method, 161–162 private access level, 234–237 private access modifier, 70, 181, 188, 199,

211, 283, 381 private field, 208–209 private keyword, 176, 325 private modifier, 69–70, 211, 234, 297 private property, 211, 535 processing list items, List<T> collection

class, 571–572 ProcessorCount property, Environment

class, 851 prod variable, 189 prod.ItemsInStock field, 189 Product class, 186, 189, 191, 195, 198, 205,

211, 220, 222, 226 Product struct, 372 Product values, 372, 376–377 ProductCategory property, 195 Product.ItemsInStock property, 224 productName field, 184–186 Product.ProductCategory field, 195 ProductResult type, 232 productSupplier field, 185–186 programming tasks, 46–60

assigning values, 46–47 iterating data items, 53–60

using a do...while loop, 58 using a for each loop, 56–57 using a for loop, 53–56 using a while loop, 59–60

making comparisons, 47–49 performing selections, 49–53

adding else clauses, 51 adding else if clauses, 51 switch statements, 51–53

programs compiling and running, 14 stand-alone, 1069–1083

adding controls, 1072–1074 adding Menu items, 1077 adding StatusBar items, 1076–1077 creating projects, 1069–1072 managing focus, 1081–1082 setting control properties, 1074–1076 setting program icons and Window

names, 1082–1083 setting tab order, 1077–1078 wiring controls, 1078–1081

testing, 1086 Web Forms, 1099–1108

adding controls, 1102–1104 creating projects, 1099–1102 setting control properties, 1104–1106 setting focus, 1107–1108 setting tab order, 1106 testing, 1108 wiring Button control, 1107

projecting data, with LINQ, 876–881 anonymous types, 877–879 derived data, 879–881 single member, 876–877

projects, creating, 1069–1072, 1087–1091 properties, 204–214

allowing classes to read and modify, 188–189

asymmetric, 209 automatically implemented, 208 computed, 209–210 exceptions from trigger method using,

792–794 exposing with field values, 189–191 field-backed, 204–207 initializing at constructions, 274–275 mapping property typse to field types,

210 modifiers, 211–214

abstract, 213 access, 210–211 sealed keyword, 213 static keyword, 214 virtual and override, 212–213

specifying, 359–360 testing for attributes applied to, 528–529 using, 207–208 for WebClient class, 677–678

� INDEX

1266

Properties window, 12, 1076, 1078, 1222 Property value, 536 Protect method, 1192–1193 protected access level, 234–235 protected access modifier, 70, 181, 199, 210,

283 protected internal access modifier, 70, 181,

199, 211, 283 protected internal modifier, 234 protected keyword, 283, 325 protected modifier, 69–70, 234 ProtectedData class, 1192 ProtocolVersion property, 703 public access level, 237 public access modifier, 70, 181, 199, 210–

211, 272, 283, 361, 371, 381 public const field, 197 public field, 184, 189 public keyword, 133–134, 176, 302, 325 public method, 1226 public modifier, 69–70, 188, 211, 234, 274 public property, 208 public static field, 195, 197 publishing EventHandler pattern events,

317–321 PublishServer class, 697 punctuators, 39–40 Push( ) method, 454, 457, 461, 473, 604–605

� Q queries, 944–963

create objects from XML, 949–950 creating XML from LINQ queries, 946–

949 grouping XML, 958–960 for LINQ, 870–874

compiler-inferred types, 873–874 range variable type, 870–873 result type, 870–872

modifying and transforming XML data, 950–956

adding elements to XML, 950–952 changing and deleting elements,

955–956 creating CSV files from XML, 952–

953 creating XML from CSV data, 953–

954 performing, 915–918

performing without results, 922–923 preserving order in, 920–921 querying XML for data, 945 sorting XML, 957–958 using Parallel LINQ (PLINQ) to process

XML, 960 querying

compiling queries, 985–988 data, 985–993

compiling queries, 985–988 querying stored procedures, 989–993 querying views, 988–989

stored procedures, 989–993 using navigation properties, 982 views, 988–989

QueryString property, 677–678, 680, 703 Queue class, 619 Queue<int> collection, 810–811 Queue<T>( ) method, 602 Queue<T> collection class, 602–604 Queue<T>(IEnumerable<T>) method, 602 Queue<T>(int) method, 602 queues, 602–606 Quit menu, wiring, 1078–1079

� R Random class, 848–849 random numbers, secure, 1197–1198 RandomNumberGenerator class, 1197–1198 range variable type, for LINQ, 870–873 Rattz, Joe, 27, 863 RC2 class, 1187 RC2CryptoServiceProvider class, 1187 Read( ) method, 669, 844, 1012 Read value, 661 ReadAllBytes(string) method, 640 ReadAllLines(string) method, 641 ReadAllText(string) method, 641 ReadBlock(char[], int, int) method, 673 ReadBoolean( ) method, 669 ReadByte( ) method, 652, 656, 669 Read(byte[], int, int) method, 652, 669 ReadBytes(int) method, 669 ReadChar( ) method, 669 Read(char[], int, int) method, 669 ReadChars(int) method, 669 ReadDecimal( ) method, 669 ReadDouble( ) method, 669

� INDEX

1267

readers, 666–673 reading binary data, 667–669 reading textual data, 670–673 System.IO.File class, 642

reading binary data, 667–669 characters, 492–493 from console, 843–845 fields, 140–142 from streams, 656 textual data, 670–673

ReadInt16( ) method, 669 ReadInt32( ) method, 669 ReadInt64( ) method, 669 ReadKey( ) method, 844–845 ReadKey(bool) method, 844 ReadLine( ) method, 672–673, 844 ReadLines(string) method, 641 ReadObject method, 762 read-only fields, 196–198

const keyword, 196–197 readonly keyword, 197–198

readonly keyword, 71, 196–198 read-only lists, 613–614 readonly modifier, 73–74 ReadOnly property, 1040, 1105 ReadString( ) method, 669 ReadToEnd( ) method, 673, 676 ReadUInt16( ) method, 669 ReadUInt64( ) method, 669 ReadUUnt32( ) method, 669 readValue variable, 188 ReadWrite value, 661 real number, 93 real type, 977 ReceiveAndPrintMessages method, 705 rectangular arrays, 410–415

creating with additional dimensions, 414–415

enumerating, 412–413 getting and setting values, 411 initializers, 411–412

Redirect(string) method, 704 ref keyword, 80–81 ref modifier, 243, 245 ref parameter keyword, 80 reference

parameter, 243–245 type fields, 191–193 types, 43–45 variables, 44–45

References folder, 697 Refresh( ) method, 632, 635, 637 registering data model, 1114 RegisterRoutes method, 1114 regular

expressions, 495 methods, 816

relational operators, 116–118 Release mode, 1206 ReleaseResources method, 431 Remove( ) method, 556, 942 RemoveAll( ) method, 942 RemoveAt(int) method, 555, 582, 1199 RemoveAttributes( ) method, 942 RemoveFirst( ) method, 577 Remove(int, int) method, 497, 503 Remove(int) method, 497 RemoveLast( ) method, 577 RemoveRange(int, int) method, 557 Remove(T) method, 553 Remove(TKey) method, 586, 590 RemoveWhere method, 602 RemoveWhere(Predicate<T>) method, 601 removing

dictionary items, Dictionary<TKey, TVal> collection class, 592

list items LinkedList<T> collection class, 576–

580 List<T> collection class, 557–559 SortedList<TKey, TVal> collection

class, 582–585 Renamed event, 646 Renamed value, 647 RenamedEventArgs class, 646 ReplaceAll(object[]) method, 942 ReplaceAttributes(object[]) method, 942 Replace(char, char) method, 497, 503 Replace(string, string) method, 497, 503, 632 Replace(string, string, string) method, 639 replacing data in streams, 656–657 Request property, 702 Requires method, 1223 Reset( ) method

IEnumerable<T> interface, 867 StopWatch class, 713

ResetColor( ) method, Console class, 847 Resize method, 406 resizing arrays, 402–406 Response property, 702

� INDEX

1268

ResponseHeaders property, for WebClient class, 680–681

Restart( ) method, StopWatch class, 713 Result method, 777 result ordering, 918–921 Result property, 682, 684, 777, 789, 797–798 result type, for LINQ, 870–872 result variable, 308 resultCount variable, 898 results

Boolean, 128–129 enumerating, 978 and LINQ, 867–869

enumerating manually, 867–868 using as data sources, 868–869

of methods, 256–257 performing queries without, 922–923 from Task class, 776–778

rethrowing exceptions, 436–438 retrieving

dictionary items, Dictionary<TKey, TVal> collection class, 592

list items LinkedList<T> collection class, 576–

580 List<T> collection class, 557–559 SortedList<TKey, TVal> collection

class, 582–585 return keyword, 77, 225, 233, 238, 256, 292,

331, 335 Return Value value, 536 Reverse( ) method, 565–566, 601 Reverse(int, int) method, 565 RIA (Rich Internet Applications), 1140 right-shift operator, 119 RijndaelManaged class, 1187 RIPEMD160 class, 1193 RIPEMD160Managed class, 1193 Root property, 635 Round(decimal) method, 108 Round(double) method, Math class, 852 row objects, 975–976 Rows property, 1026 rules

selecting, 1214–1215 violations, 1216–1220

suppressing every occurrence, 1219–1220

suppressing single occurrences, 1217–1219

Run as administrator context menu option, 704

Run Code Analysis item, 1215 runtime checker, 1229–1230

� S s format component, TimeSpan, 722 Sales Staff entry, 1118 Sales Staff table, 1120 sameRefs variable, 48 sample code, downloading, 10 Save All menu option, 12 Save method, 934–936 Save Project dialog box, 12 SaveChanges method, 993, 996–998, 1000,

1058, 1144 SaveOptions parameter, 936 Save(Stream, SaveOptions) method, 935 Save(Stream) method, 935 Save(string, SaveOptions) method, 935 Save(string) method, 935 Save(TextWriter, SaveOptions) method,

935 Save(TextWriter) method, 935 sbyte keyword, 62, 92 sbyte type, 43, 93–94, 98–99 ScaffoldAllTables property, 1114, 1120 ScaffoldColumn attribute, 1120 ScaffoldTable attribute, 1121 Scalars menu, 991 scopes, of variables, 255–256 sealed classes, 74, 179 sealed keyword, 74, 156, 211, 213, 259, 375,

534 sealed method, 301 sealed modifier, 74, 179, 258–259, 267,

301 sealing methods, 267–268 searching strings, 499–500 SearchOption enumeration, 626 Seconds property

DateTime, 725 TimeSpan, 716

Secure Hash Algorithm (SHA), 1194 secure random numbers, 1197–1198 SecureString class, 1198–1200 security. See also cryptography

secure random numbers, 1197–1198 with strings, 1198–1200

� INDEX

1269

using hash codes, 1193–1197 generating, 1194–1196 verifying, 1196–1197

Security value, 650 Seek method, 655–656 seeking within streams, 655 Seek(long, SeekOrigin) method, 652 SeekOrigin values, 652, 655 select clause, 871, 877, 881, 909, 911, 919,

947, 960, 978, 988 select keyword, 865, 891, 893 Select method, 892–893, 907 select statement, 891 SelectAll method, 1082 SelectedItem property, 1148 selection keywords, 75 selection statements, 40 SelectionChanged event, 1148 SelectionChanged property, 1147 selections, 49–53

adding else clauses, 51 adding else if clauses, 51 switch statements, 51–53

SelectiveImpl class, 301 Sells, Chris, 28 semicolons (;), 39, 54 SendMessages method, 706 SequenceEqual method, 1197 Serializable attribute, 736–737, 739–741,

745, 753, 756, 761 serialization, 735–765

binary, 736–752 callback attributes for, 745–747 graphs of objects, 739–741 multiple objects to single stream,

741–744 selected fields only, 744–745 version tolerance for, 748–752

Data Contract Serializer, 760–765 generating JSON, 763–764 generating .NET-specific XML, 762–

763 generating portable XML, 761–762 preparing class for, 760–761

SOAP, 752–755 XML, 755–760

changing name for elements and attributes, 759–760

mapping members to elements and attributes, 758

selected fields only, 757

Serialize method, 738, 756 Server Explorer/Database Explorer window,

1002, 1004 service contract, for WCF server, 694–696 Service References folder, 698 ServiceContract attribute, 694 ServiceHost constructor, 696 ServiceInterval field, 143–144 serviceInterval variable, 143–144 set accessor, 208–209, 211, 215–216 set keyword, 207–208, 213 set request, 217 set value keyword, 85 SetAt(int, char) method, SecureString class,

1199 setButtonState method, 1155 SetCreationTime(string, DateTime)

method, 628, 639 SetCurrentDirectory(string) method, 629 SetEnvironmentVariable(string, string)

method, Environment class, 851 SetEquals(IEnumerable<T>) property, 596 SetLastAccessTime(string, DateTime)

method, 628, 639 SetLastWriteTime(string, DateTime)

method, 628, 639 SetLength(long) method, 652 SetObserved method, 795 sets, 595–602

HashSet<T> collection class, 597–599 ISet<T> interface, 595–597 SortedSet<T> collection class, 599–602

Settings submenu, 9 SHA (Secure Hash Algorithm), 1194 SHA1 class, 1193 SHA1Cng class, 1193 SHA1CryptoServiceProvider class, 1193 SHA1Managed class, 1193 SHA256 class, 1193 SHA256Cng class, 1193 SHA256CryptoServiceProvider class, 1193 SHA256Managed class, 1193, 1195 SHA384 class, 1194 SHA384Cng class, 1194 SHA384CryptoServiceProvider class, 1194 SHA384Managed class, 1194 SHA512 class, 1194 SHA512Cng class, 1194 SHA512CryptoServiceProvider class, 1194 SHA512Managed class, 1194 short keyword, 68, 92

� INDEX

1270

short type, 93–94, 98–99, 101 short value, 43, 669 ShouldExitCurrentIteration property, 828–

829 Show method, 1140 Shutdown method, 1078 signed integer values, 93 Silver argument, 138 Silverlight, 1125–1157

out-of-browser support, 1149 configuring, 1150–1151 features for, 1157 installation of, 1153–1156 using program out-of-browser,

1152–1153 Swimming Calculator example, 1126–

1140 Button control for, 1134 Button event for, 1136–1137 Child Window for, 1137–1140 creating project, 1126–1128 Label controls for, 1132–1133 layout for, 1128–1136 TextBlock control for, 1133–1134 TextBox controls for, 1131–1132

tools, 10 WCF RIA Service, 1140–1157

client for, 1144–1149 creating project, 1141 data model for, 1141 domain service class, 1142–1144 testing application, 1149

Silverlight Application template, 1126 Silverlight Child Window template, 1138 Silverlight tab, Visual Studio, 1150 Sin(double) method, Math class, 852 single-dimensional arrays, 409 single-threaded, vs. multi-threaded, 768–

771 Site.master file, 1122 Size value, 650 SOAP serialization, 752–755 SoapFormatter class, 754–755 socket programming, 684–693

parallel server for, 691–693 TcpClient class for, 689–691 TcpListener class for, 685–688

software, installing, 7–10 downloading sample code and data,

10 Silverlight tools, 10

SQL Server 2008, 9–10 Visual Studio 2010, 7–9

Solution Explorer window, 753, 760 Sort( ) method, 560, 565–566, 581, 610 Sort(Comparison<T>) method, 565 SortedDictionary<TKey, TVal> collection

class, 593–595, 619 SortedDictionary<TKey, TVal>( ) method,

594 SortedDictionary<TKey,

TVal>(IDictionary<TKey, TVal>, IComparer<TKey>) method, 595

SortedDictionary<TKey, TVal>(IDictionary<TKey, TVal>) method, 595

SortedList class, 619 SortedList<string, string> class, 582, 585 SortedList<TKey, TVal> collection class,

581–585 adding list items, 582–585 removing list items, 582–585 retrieving list items, 582–585

SortedList<TKey, Tval>( ) method, 581 SortedList<TKey, TVal>(IComparer<TKey>)

method, 581 SortedList<TKey, TVal>(IDictionary<TKey,

TVal>, IComparer<TKey>) method, 581 SortedList<TKey, TVal>(IDictionary<TKey,

TVal>) method, 581 SortedList<TKey, TVal>(int,

IComparer<TKey>) method, 581 SortedList<TKey, TVal>(int) method, 581 SortedSet<string> class, 601, 608 SortedSet<T>( ) method, 600 SortedSet<T> collection class, 599–602, 608 SortedSet<T>(IComparer<T>) method, 600 SortedSet<T>(IEnumerable<T>,

IComparer<T>) method, 600 SortedSet<T>(IEnumerable<T>) method,

600 Sort(IComparer<T>) method, 565 sorting

arrays, 400–401 list items, List<T> collection class, 565–

570 Sort(int, int, IComparer<T>) method, 565 Sort(T[], IComparer<T>) method, 611 Sort(T[]) method, 611 Source property, 428 spec variable, 146 specialization of methods, 268–269

� INDEX

1271

Speed property, NetworkInterface class, 859 Split method, 954 Split(params char[]) method, 497 SQL Server 2008, 9–10 SqlCommand parameter, 1014 SqlCommandBuilder class, 1024 SqlConnection constructor, 1010 SqlDataAdapter class, 1013–1014, 1022 SqlDataAdapter.Update method, 1024,

1028–1029 SqlDataReader class, 1012 Stack class, 619 Stack<T>( ) method, 604 Stack<T> collection class, 604–606, 619 Stack<T>(IEnumerable<T>) method, 604 Stack<T>(int) method, 604 StackPanel controls, for Swimming

Calculator example, 1130–1131 stacks, 602–606 StackTrace property, 428 stand-alone programs, 1069–1083

adding controls, 1072–1074 Menu items, 1077 StatusBar items, 1076–1077

creating projects, 1069–1072 managing focus, 1081–1082

focusing on first controls, 1081 selecting TextBox text on focus, 1082

setting control properties, 1074–1076 configuring Button, 1076 configuring Label controls, 1074 configuring TextBlock controls, 1075 configuring TextBox controls, 1074–

1075 setting program icons and Window

names, 1082–1083 setting tab order, 1077–1078 wiring controls, 1078–1081

wiring Button, 1080–1081 wiring Quit menu, 1078–1079 wiring TextBox controls, 1079–1080

Start( ) method for StopWatch class, 713 for Task class, 773–774

Start Debugging option, Visual Studio, 34 Start Without Debugging menu option, 14,

34, 697, 1112, 1123 StartNew( ) method, 713, 779, 783 StartsWith(string) method, 499 State property, 1006

statements, 14–15 class, 15 namespace, 15 types of, 40

stateObject parameter, 779 static checker, 1226–1228 static classes, creating, 176–177 static code analysis, 1214–1220

performing, 1215–1216 rule violations, 1216–1220

suppressing every occurrence, 1219–1220

suppressing single occurrences, 1217–1219

selecting rules, 1214–1215 static constructor, 287–289 static fields, 147–148, 184, 194–197 static keyword, 148, 194, 211, 214, 257,

288 static modifier, 74, 257–258 static Parse method, 126 static properties, 195 status, of Task class, 780–782 Status property, 780–781, 797–798 StatusBar control, 1136–1137 StatusBar items, adding, 1076–1077 StatusBarItem control, 1076–1077 StatusCode property, 704 StatusDesdcription property, 704 StatusStrip, Windows Forms example

program with, 1042–1043 StockCode property, 909 StockLevel element, 945, 960, 962 Stop( ) method

ParallelLoopState class, 828–829 StopWatch class, 713

StopWatch class, 711–715, 769 stored procedures, querying, 989–993 str variable, 396 Stream class, 650–651, 653, 658, 661, 673,

819 Stream parameter, 663, 665, 670 Stream.CopyTo method, 703 StreamingContext struct, 747 StreamReader class, 634, 670, 672–673, 688,

691 streams, 650–666

base streams, 657–662 FileStream class, 660–662 MemoryStream class, 657–659

� INDEX

1272

streams (cont.) pass-through streams, 663–666

buffered pass-through stream, 663–664

compressing data with, 664–666 System.IO.File class, 642 System.IO.Stream class, 653–657

reading from streams, 656 replacing data in streams, 656–657 seeking within streams, 655 writing to streams, 654–655

StreamWriter class, 634, 642, 670–672, 688, 691

StreamWriter WriteLine methods, 670 StreamWriter(Stream) method, 670 StreamWriter(string, bool) method, 670 StreamWriter(string) method, 670 string argument, 105, 217 string arrays, 388–389, 391, 393, 395, 399,

496–497, 610, 825 string class, 303, 492–493, 499–500, 502, 506,

954 string field, 490, 737 'string' format component, TimeSpan, 722 string keys, 585 string keyword, 67, 486 string literals, 37, 487–488, 494, 502 string parameters, 260, 278, 496, 503, 526,

635, 682, 935, 938, 1209 string property, 210 string reference type, 44 string result, 217 string type, 126, 129, 145, 389, 502, 507, 573,

601, 669, 976 string values, 53, 210, 455, 459, 486, 488, 496,

516 string variable, 487–488, 492 StringBuilder class, 502–506 StringBuilder object, StringBuilder class,

502–506 creating, 502 using Append and Insert methods, 505–

506 using StringBuilder indexer, 506

StringBuilder type, 43, 65 StringBuilder values, 502 StringBuilder variables, 47, 339 StringBuilder.AppendFormat method, 508 string.Empty field, 489–490 string.Format method, 210, 508, 518 string.Length property, 492

StringLengthComparer class, 570, 607 StringLengthEqualityComparer class, 609 strings, 481–518

characters, 482–486 expressing using literals, 482–483 performing operations on, 483–484 using struct members, 484–486

class members, 496–501 manipulating strings, 496–499 other class members, 500–501 searching strings, 499–500

converting to bytes, 849–850 DateTime, formatting, 730–733 expressing using string literals, 486–488 formatting, 507–518

composite formatting, 507–511 creating string representations of

custom types, 514–516 formatting types, 511–514 performing custom composite

formatting, 516 performing operations on, 488–494

combining strings, 491–492 comparing strings, 489–490 enumerating strings, 493 reading individual characters, 492–

493 using strings in switch statements,

494 regular expressions, 495 security with, 1198–1200 StringBuilder class, 502–506 TimeSpan, formatting, 720–723

struct constraint, 464 struct feature, 43 struct keyword, 67–68, 371, 464 struct members, 103–109

getting range of supported values, 104 Parsing numeric values, 105–106 type-specific members, 107–109 using, 129–130, 484–486

struct types, 103 Struct value, 536 structs, 371–380

copying, 376–380 defining and instantiating, 371–374 differences with classes, 374–376

base structs and inheritance, 375 fields, 375 struct constructors, 375–376

generic, creating, 472

� INDEX

1273

Substring(int, int) method, 497 Substring(int) method, 497 Subtraction operator, 110 suffixes, literal, 95–96 Sum( ) method, System.Linq.Enumerable

class, 905 SumSequence iterator block, 296 Supplier class, 185–186, 193 Supplier constructor, 186 Supplier type, 185 supplierName field, 186 SuppressKeyPress property, 1050 SuppressMessage attribute, 1218–1219 SwimCalculator project, 1070, 1099, 1126–

1128, 1150 SwimCalculatorTestPage.aspx file, 1128,

1152 SwimCalculatorTestPage.html file, 1128 SwimCalculator.Web project, 1128, 1152 Swimming Calculator example, 1126–1140

Button control for, 1134 Button event for, 1136–1137 Child Window for, 1137–1140 creating project, 1126–1128 Label controls for, 1132–1133 layout for, 1128–1136

Grid columns, 1128–1130 StackPanel controls, 1130–1131

TextBlock control for, 1133–1134 TextBox controls for, 1131–1132

switch selection keyword, 75 switch statements, 49, 51–53, 75–77, 382,

484, 494 SymmetricAlgorithm class, 1186–1187 SymmetricExceptWith(IEnumerable<T>)

method, 596 synchronization keywords, 79 synchronous methods, 816 System class, 352 System namespace, 82, 103, 318, 338–340,

346, 434, 438, 737 System.Action class, 326–327 System.AggregateException class, 446 System.ApplicationException class, 438 System.ArgumentNullException exception,

106 System.Array class, 394, 400, 404–406, 413,

609–611 System.Array members, 400–408

finding items in arrays, 406–408 processing elements in arrays, 401–402

resizing and copying arrays, 402–406 sorting arrays, 400–401

System.Array method, 612 System.Array.Find method, 407 System.Array.Resize method, 405 System.Array.Sort method, 400 System.Attribute class, 520, 532 System.AttributeTarget enum, 536 System.BitConverter class, 1198 System.Boolean struct, 62, 127, 129 System.Byte type, 92 System.Char struct, 482, 484–485 System.Collections namespaces, 291, 617,

902 System.Collections.ArrayList class, 617 System.Collections.Concurrent namespace,

811 System.Collections.Generic namespace,

409, 553, 617, 811, 864, 866 System.Collections.Generic.IEnumerable<T

> interface, 56, 296 System.Collections.Generic.IEnumerator<T

> interface, 291 System.Collections.IEnumerator interface,

291, 396 System.Collections.ObjectModel.ReadOnly

Collection class, 614 System.Collections.Specialized namespace,

617 System.Collections.Specialized.NameValue

Collection class, 678 System.Comparison class, 570 System.Comparison<T> class, 568–569 System.ComponentModel namespace, 683,

1117 System.ComponentModel.DataAnnotations

namespace, 1117 System.Configuration namespace, 1010 System.Console class, 82, 135, 269, 338, 340,

352, 843 System.ConsoleColor enum, 847 System.Console.WriteLine method, 188, 338 System.Convert class, 834–835 System.Converter class, 612 System.Data namespace, 1006, 1015 System.Data.ConnectionState enumeration,

1006 System.Data.DataRowExtensions class,

1016 System.Data.DataSet class, 1001, 1012 System.Data.Objects namespace, 986

� INDEX

1274

System.Data.Objects.DataClasses namespace, 980

System.Data.Objects.ObjectSet<T> collection, 975

System.Data.OracleClient namespace, 1006 System.Data.SqlClient namespace, 1006,

1015 System.DateTime struct, 628, 723 System.Decimal type, 93 System.Delegate class, 313 System.Delegate properties, 315 System.Diagnostics namespace, 857, 1202 System.Diagnostics.CodeAnalysis

namespace, 1218 System.Diagnostics.Contracts namespace,

1221 System.Diagnostics.ProcessStartInfo class,

1200 System.Diagnostics.StopWatch class, 712 System.DivideByZero exception, 1203, 1205 System.Double type, 93 System.Enum class, 522 System.Environment class, 850–851 System.EventArgs class, 317 System.Exception class, 77, 425, 427–429,

433–435, 437–438 System.FlagsAttribute class, 520 System.FormatException, 106, 836 System.Func class, 328 System.Func delegates, 328 System.GC.Collect method, 540 System.IComparable<T> interface, 607 System.IConvertible interface, 834 System.ICustomFormatter interface, 516 System.IDisposable interface, 544 System.IFormatProvider interface, 516 System.IndexOutOfRangeException class,

389 System.Int16 type, 92 System.Int32 struct, 103 System.Int32 type, 92 System.Int64 type, 92 System.InvalidCastException, 902 System.InvalidOperationException, 842 System.IO namespace, 630, 666 System.IO.Compression namespace, 664 System.IO.Directory class, 622–630 System.IO.DirectoryInfo class, 635–636 System.IO.File class, 639–642

file convenience methods, 640–642 stream, reader, and writer methods, 642

System.IO.FileInfo class, 631 System.IO.FileSystemEventArgs class, 646 System.IO.FileSystemInfo class, 637 System.IO.FileSystemWatcher class, 645–

646, 648 System.IO.Path class, 643–644 System.IO.SearchOption enumeration, 626 System.IO.SeekOrigin enumeration, 655 System.IO.Stream class, 653–657

reading from stream, 656 replacing data in stream, 656–657 seeking within stream, 655 writing to stream, 654–655

System.Linq namespace, 398, 864 System.Linq.Enumerable class, 891, 893,

899 System.Linq.ParallelEnumerable class, 915 System.Linq.Xml class, 940 System.Math class, 852 System.Media namespace, 1050, 1080 System.MyConsoleHelper type, 346 System.Net.Dns class, 707, 816 System.Net.HttpListener class, 700 System.Net.NetInformation namespace,

857 System.Net.Sockets namespace, 686 System.Net.Sockets.UdpClient class, 705 System.Net.WebClient class, 675 System.NotSupportedException class, 614 System.Nullable<T> struct, 841 System.NullReferenceException class, 423 System.Numerics assembly, 126 System.Numerics.BigInteger struct, 126 System.Object class, 155, 164–165, 169–170,

455, 461, 511, 514, 533 System.ObsoleteAttribute class, 521–522 System.OverflowException, 101, 106, 836 System.Predicate class, 448 System.Predicate delegate, 408 System.Predicate parameter, 448 System.Predicate<T> delegate, 407 System.Random class, 848 System.Reflection.MethodInfo class, 315 System.Runtime.Serialization assembly, 760 System.Runtime.Serialization namespace,

738, 747, 761 System.Runtime.Serialization.Binary

namespace, 738 System.Runtime.Serialization.Formatters

namespace, 750

� INDEX

1275

System.Runtime.Serialization.Formatters.Binary namespace, 339

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter class, 340

System.Runtime.Serialization.Formatters.Soap assembly, 753

System.Runtime.Serialization.Json namespace, 764

System.SByte type, 92 System.Security assembly, 1192 System.Security namespace, 1198 System.Security.Cryptography namespace,

1186, 1189, 1192–1193, 1197 System.ServiceModel assembly, 693 System.ServiceModel namespace, 694 System.Single type, 93 SystemSounds class, 1050 SystemSounds.Beep.Play method, 1080 System.String class, 303, 486, 496, 499, 501 System.String methods, 497 System.String type, 67 System.SystemException class, 438 System.Text namespace, 338, 378, 502 System.Text.Encoding class, 706, 849 System.Text.RegularExpressions.Regex

class, 495 System.Text.StringBuilder class, 339, 503–

504 System.Threading namespace, 783, 794 System.Threading.Tasks namespace, 772,

795 System.Threading.Tasks.Parallel class, 824 System.Threading.Tasks.TaskStatus

enumeration, 780 System.Threading.WaitHandle object, 821 System.TimeSpan struct, 715 System.Tuple class, 461, 838 System.Type class, 523–524 System.Type parameters, 524, 526 System.UInt16 type, 92 System.UInt32 type, 92 System.UInt64 type, 93 System.Uri parameter, 682 System.ValueType class, 103, 375 System.WeakReference class, 547 System.Windows.Application class, 1078 System.Windows.Form class, 1063 System.Windows.Forms namespace, 1035,

1048 System.Windows.Forms.Control class, 1048

System.Windows.Forms.KeyEventHandler delegate, 1048

System.Windows.Input namespace, 1080, 1093

System.Windows.Media.Animation namespace, 1087

System.Xml.Linq class, 947 System.Xml.Linq namespace, 925–926, 944,

950 System.Xml.Linq.SaveOptions enum, 936 System.Xml.Serialization namespace, 757 System.Xml.Serialization.XmlSerializer

class, 755 Sytem.Collections namespace, 409

� T T? nullable form, 841 T specifier, DateTime, 730 tab order, for Windows Forms controls,

1045 TabIndex property, 1077–1078, 1106 tables

changing names, 1117–1118 properties, 975–976, 1015 selecting to be displayed, 1120–1121

tabs, setting order, 1077–1078, 1106 TabStop property, 1045 Take method, 1020 Tan(double) method, Math class, 852 Target property, 314–315, 547 TargetSite property, 428 Task class

cancelling multiple tasks, 786–787 in single statement, 784–786

continuations of chains of, 800–801 results for, 798–800 selective, 801–803 simple, 796–797

creating object, 772–773 exceptions from trigger method, 789–

794 from multiple tasks, 790–791 using custom exception escalation

policy, 794–795 using properties, 792–794

exceptions in task body, 787–788

� INDEX

1276

Task class (cont.) getting

details of antecedent, 797–798 status of, 780–782

passing parameters to, 778–780 results from, 776–778 sharing data between tasks, 803–809

avoiding synchronization, 808–809 creating critical region, 806–808 and critical region, 806

Start( ) method for, 773–774 Wait( ) method for, 774–776

Task constructor, 779 Task Parallel Library (TPL), 27, 705, 767, 915 Task parameter, 779 Task property, 792 Task variable, 777 Task<T> class, 776–777, 782 Task<T>.Factory.FromAsync method, 823 TaskContinuationOptions enum, 802 Task.ContinueWith method, 796, 802 Task.Factory.FromAsync method, 815 Task.Factory.StartNew method, 773 tasks, mixing with parallel loops, 823–824 TaskScheduler class, 794 TaskScheduler.UnobservedTaskException

event, 794 TaskStatus enumeration, 780 Task.Status property, 780, 784 Task.Wait method, 820 Task.WaitAll method, 775, 789 TCP (Transmission Control Protocol), 684,

704 TcpClient class, for socket programming,

689–691 TcpListener class, for socket programming,

685–688 Territories table, 979 TestForClassAttribute method, 523–524 TestForMethodAttribute method, 531 testing and debugging, 1201–1230

attributes, 522–532 applied to classes, 522–525 applied to fields, 525–527 applied to methods, 530–532 applied to properties, 528–529

code contracts, 1221–1230 installing and enabling, 1221–1222 runtime checker, 1229–1230 static checker, 1226–1228

writing assertion contracts, 1224–1225

writing invariant contracts, 1225–1226

writing postcondition contracts, 1223–1224

writing precondition contracts, 1222–1223

Debug class, 1202–1212 categories, 1211–1212 Debug listeners, 1207–1209 disabling Debug statements, 1206 indenting Debug output, 1211–1212 making assertions, 1204–1206

object types, 170–172 static code analysis, 1214–1220

performing, 1215–1216 rule violations, 1216–1220 selecting rules, 1214–1215

Trace class, 1212–1214 TexBox control, 1051 Text namespace, 339 Text properties group, 1075 Text property, 1039, 1043, 1052, 1080, 1104,

1106–1107, 1132, 1134, 1140 text type, 976 TextAlign property, 1039–1040 TextBlock controls

configuring, 1075 selecting text on focus, 1082 for Swimming Calculator example,

1133–1134 TextBox, Windows Forms example program

with, 1039, 1048–1051 TextBox controls

configuring, 1074–1075, 1104–1106 for Swimming Calculator example,

1131–1132 wiring, 1079–1080

TextMode property, 1105 textual data, reading and writing, 670–673 TextWriter class, 935 TextWriterTraceListener class, 1207–1209 TextWriterTraceListener constructor, 1208 TextWriterTraceListener(Stream)

constructor, 1208 TextWriterTraceListener(string)

constructor, 1208 TextWriterTraceListener(TextWriter)

constructor, 1208 this keyword, 86, 200, 254, 276–277, 281, 302

� INDEX

1277

this modifier, 301 this parameter, 215 this.myField field, 200 throw exception handling keyword, 77–78 throw keyword, 78, 432, 436–437, 439, 447 throw statement, 433, 437 throwing exceptions, 432–451

aggregating exceptions, 446–451 creating and throwing custom

exceptions, 438–441 creating exception chains, 444–446 mapping exception types, 442–444 rethrowing exceptions, 436–438

Ticks property, TimeSpan, 716 time and dates, 711–733

creating and using DateTime values, 724–726

formatting DateTime strings, 730–733 measuring small amounts of time, 712–

715 performing operations on DateTime

values, 727–730 working with periods of time, 715–723

creating and using TimeSpan values, 715–718

formatting TimeSpan strings, 720–723

performing operations on TimeSpan values, 719–720

TimeOfDay property, DateTime, 725 TimeSpan operators, 711, 719 TimeSpan strings, formatting, 720–723 TimeSpan structure, 711, 715, 1088 TimeSpan values

creating and using, 715–718 performing operations on, 719–720

TimeSpan.ToString method, 721–722 Title field, 1018, 1028 Title property, 847, 1082 TKey parameter, 461, 465, 581 TKey type, 582, 585–586, 589–590 To property, 1088 ToArray( ) method, 658, 900, 1190 ToCharArray( ) property, 501 Today property, 724 ToDictionary(Func(T)) method,

System.Linq.Enumerable class, 900 ToInt32 method, Convert class, 834 ToInt64 method, Convert class, 834–835 Token property, 783

Token.IsCancellationRequested property, 784

ToList( ) method, System.Linq.Enumerable class, 900

ToLower( ) method, 497 ToLower(char) method, 485 Tools menu, 9 ToolStripStatusLabel control, 1044 TopDirectoryOnly value, 626 ToString( ) method, 129, 428–429, 505, 515–

516, 522, 533, 929, 1210 ToString(string) method, 103 TotalDays property, TimeSpan, 716 TotalHours property, TimeSpan, 716 TotalMilliseconds property, TimeSpan, 716 TotalMinutes property, TimeSpan, 716 TotalSeconds property, TimeSpan, 716 TotalValueOfStock property, 209 ToUpper( ) method, 497 ToUpper(char) method, 485 TOut parameter, 572–573 TPL (Task Parallel Library), 27, 705, 767, 915 Trace class, 1212–1214, 1224 TRACE constant, 1214 Trace method, 1221 Trace statement, 1213 TRACE symbol, 855 Transmission Control Protocol (TCP), 684,

704 Trim( ) method, 497 TrimEnd( ) method, 497 TrimExcess( ) method, 572–573, 585 TrimStart( ) method, 497 TripleDES class, 1187 TripleDESCryptoServiceProvider class, 1187 TripPrinter class, 161–162 true, false literal keyword, 83 TrueForAll method, 571–572 TrueForAll(Predicate<T>) method, 571 TrueForAll(T[], Predicate<T>) method, 611 TrueString field, 129 Truncate method, 108 Truncate value, 660 Truncate(decimal) method, 108 Truncate(double) method, Math class, 853 try block, 422 try exception handling keyword, 78 try keyword, 421–422 try statements, 78, 256, 421–424, 427, 441,

450, 788, 793 TryGetValue method, 584–585

� INDEX

1278

TryGetValue(Tkey, out TVal) method, 582, 586, 590

TryParse method, 103, 129, 834 TryParse(string, out bool) method, 129 TryParse(string, out T) method, 103 TryPerformCalculation method, 246–247 TryXXX method, 246 TryXXX pattern, 245–246 tt format component, DateTime, 733 Tuple class, returning multiple results

using, 836–838 Tuple.Create method, 838 TVal parameter, 461, 465 TVal type, 582, 585–586, 589 type ambiguity, 349 type array, 388 type conversions

exceptions, 169–170 numeric, 98–101

type keywords, 61–69 bool, 62 byte, sbyte, 62 char, 62 class, 63 decimal, double, float, 63 delegate, 64 dynamic, 64–65 enum, 65 interface, 65–66 object, 66–67 short, ushort, int, uint, long, ulong, 68 string, 67 struct, 67–68 var, 69 void, 68

type name collision, 349 type safety, 22–23 type variance, 472–477

combining contravariance and covariance, 477

contravariance, 476–477 covariance, 475–476

typeof keyword, 84, 756, 762 typeof operator, 524 typeof(Calculator) method, 525 typeof(EmployessMetaData) type, 1118 types, 41–46

adding to existing namespaces, 346 aliasing generic, 839–840 converting between, 834–836

definite assignment and null references, 45–46

disambiguating, 347–353 with aliases, 349–350 aliasing namespaces, 350–351 with fully qualified names, 349 resolving type or namespace hiding,

351–353 nullable, 841–843 reference, 43–45 underlying, 382–383 value, 42–43

� U U suffix, 96 UDP (User Datagram Protocol), 704 UdpClient class, 704–707 UdpClient.Receive method, 706 UdpClient.Send method, 706 UdpTest class, 707 uint keyword, 68, 92 uint type, 93–94, 96, 98–100 uint value, 43, 669 UL suffix, 95–96 ulong keyword, 68, 93 ulong type, 93–94, 96, 98–99 ulong value, 43, 669 unary operators, 113–116, 219–221

decrement operator, 221 increment operator, 221 minus operator, 113 negation operator, 221 negative operator, 221 NOT operator, 221

unboxing objects, 173–175 unchecked arithmetic overflow keyword, 78 unchecked block, 102–103 unchecked keyword, 102–103 underlying types and numeric values, 382–

383 Unicode characters, 35 Unindent( ) method, 1209–1210 UnionWith method, 599 UnionWith(<IEnumerable<T>) method, 596 unitsPerCrate field, 196–198 Unlock(long, long) method, 661 Unmanaged/Native Code Support, 24 UnobservedTaskException event, 795

� INDEX

1279

UnobservedTaskExceptionEventArgs class, 795

Unprotect method, 1192–1193 unsigned integer values, 93 Update method, 1026 updating fields, 186–193

allowing classes to read and modify properties, 188–189

exposing properties with field values, 189–191

field values, 186–188 reference type fields, 191–193

UploadDataCompleted event, 683 UploadDataCompletedEventArgs class,

683–684 UploadData(string, byte[]) method, 679 UploadFileAsync(Uri) method, 683 UploadFileCompleted event, 683 UploadFileCompletedEventArgs class, 683–

684 UploadFile(string, string) method, 679 UpLoadStringAsync(Uri) method, 683 UploadStringCompleted event, 683 UploadStringCompletedEventArgs class,

683–684 UploadString(string, string) method, 679 Uppercase style, 35 Url property, 702–703 UseDetailed property, 533 User class, 347 User Datagram Protocol (UDP), 704 user interfaces, 27–28 User property, Environment class, 851 UserAgent property, 703 UserControl_Loaded method, 1155 ushort keyword, 68, 92 ushort type, 93–94, 98–99 ushort value, 43, 669 using block, 1007–1008, 1010 using keyword, 82, 86, 339–340, 350, 545,

839 using statement, 343, 346, 348, 351, 545,

699, 771, 839–840, 974

� V V parameter, 107 ValidateKeyClick method, 1080 ValidateKeyPress method, 1079–1080 ValidateNumbers method, 297

ValidateResult method, 297 validating indexers, 217–218 value parameter, 207, 215, 239–243 Value property, 576, 580, 588, 841, 937–938,

942, 945, 1040, 1052 value types, 42–43 value variable, 659 values, assigning, 46–47 Values property, 582, 586, 588, 591 value-type variables, 42 var keyword, 69, 479, 873–874, 878 varchar type, 976 variables

local, 251–256 naming variables, 253–254 variable scopes and lifetimes, 255–

256 outer, capturing, 331–333

verbatim literals, 487–488 verifying hash codes, 1196–1197 Version property, Environment class, 851 version tolerance

for binary serialization, 748–752 for SOAP serialization, 754–755

VersionAdded property, 752 VerticalAlignment property, 1130, 1134 View control, 1102 View in Browser menu item, 1152 View menu, 12, 1216 View Orders links, 1116 views, querying, 988–989 virtual keyword, 73, 156, 211, 258, 266, 369–

370, 375, 468 virtual method, 300 virtual modifiers, 75, 212–213, 258, 267, 325 Visual C# templates, 11 Visual Studio 2010, 7–9 void keyword, 68, 150, 233, 237, 257, 326,

359, 747, 857 void value, 269 volatile keyword, 201 volatile modifier, 201

� W Wait( ) method, 774–777, 789 WaitAll method, 776, 790–791 WaitOne method, 821 WatcherChangeTypes enumeration, 646–

647

� INDEX

1280

WCF (Windows Communication Foundation), 693–700 client with, 697–700 RIA Service, 1140–1157

client for, 1144–1149 creating project, 1141 data model for, 1141 domain service class, 1142–1144 testing application, 1149

server with, 694–696 understanding, 29

weak references, 546 WeakReference.IsAlive property, 547 Web Forms

adding, 1109 creating data source, 1109–1111 data binding, 1108–1113

adding GridView control, 1111–1112 adding web form, 1109 creating projects and Entity Data

Model, 1109–1113 creating web forms data source,

1109–1111 testing, 1112–1113

programs, 1099–1108 adding controls, 1102–1104 creating projects, 1099–1102 setting control properties, 1104–1106 setting focus, 1107–1108 setting tab order, 1106 testing, 1108 wiring Button control, 1107

WebClient class, 675–684 events for asynchronous requests, 682–

684 methods for, 679–681 properties for, 677–678 ResponseHeaders property for, 680–681

WebClient.CancelAsync method, 684 WebClient.ResponseHeaders property, 681 where clause, 875, 877, 889, 891, 897, 918–

919, 945, 949, 954 where keyword, 463, 465, 874, 893 Where method, 892–893, 922, 962 where T : base-class constraint, 463 where T : class constraint, 463 where T : interface constraint, 463 where T : new( ) constraint, 463 where T : struct constraint, 463 where X : T constraint, 464 while Iterator keyword, 76

while loop, 293, 397, 446, 687, 810, 813, 845 Width attribute, 1072 Width property, 1084, 1088–1089, 1130–

1131, 1133–1134 Window control, 1081–1082, 1085, 1092 Window names, setting, 1082–1083 WindowHeight property, Console class, 847 WindowLeft property, Console class, 847 Windows 7, UI integration with Windows

Forms, 1063–1067 Windows Communication Foundation. See

WCF Windows DPAPI (Data Protection API), data

encryption using, 1191–1193 Windows Forms, 1033–1067

data binding with, 1053–1062 creating object data source, 1054–

1056 creating project, 1053–1054 displaying data fields, 1061–1062 filtering with LINQ, 1060–1061 formatting DataGridView control,

1056–1058 loading data, 1058 testing, 1059–1060 wiring save button, 1058–1059

example program with, 1033–1053 Button, 1041 control names, 1043–1044 creating project, 1034–1036 icon for, 1053 Labels, 1038 MenuStrip, 1041–1042 NumericUpDowns, 1040 StatusStrip, 1042–1043 tab order, 1045 testing of, 1053 TextBoxes, 1039 wiring controls, 1045–1053

Windows 7 UI integration of, 1063–1067 Windows Presentation Foundation. See

WPF WindowsAPICodePack.sln file, 1063 WindowTop property, Console class, 847 WindowWidth property, Console class, 847 wiring

Button, 1080–1085, 1107 controls, 1078–1081

Button, 1080–1081 Quit menu, 1078–1079 TextBox controls, 1079–1080

� INDEX

1281

controls for Windows Forms, 1045–1053 Button, 1051–1059 menu, 1046–1048 TextBox, 1048–1051

Quit menu, 1078–1079 TextBox controls, 1079–1080

WithExecutionMode method, 921 word event, 318 WPF (Windows Presentation Foundation),

1069–1098 animations, 1086–1090

adding, 1087–1089 combining multiple, 1089–1090 creating projects, 1087 testing, 1089

building stand-alone programs, 1069–1083

adding controls, 1072–1074 adding Menu items, 1077 adding StatusBar items, 1076–1077 creating projects, 1069–1072 managing focus, 1081–1082 setting control properties, 1074–1076 setting program icons and Window

names, 1082–1083 setting tab order, 1077–1078 wiring controls, 1078–1081

commands, 1090–1098 adding and configuring MenuItem

control, 1092 binding, 1092–1093 configuring Button controls, 1091–

1092 creating project, 1090–1091 selectively activating, 1094–1096 using to set control content, 1096

data binding, 1083–1086 formatting DataGrid control, 1084–

1085 loading data, 1085 testing program, 1086 wiring Button, 1085

Write method, 844, 1190 Write value, 661 WriteAllBytes(string, byte[]) method, 641 WriteAllLines(string,

IEnumberable<string>) method, 641 WriteAllLines(string, string[]) method, 641 WriteAllText(string, string) method, 641 Write(bool) method, 667, 844 Write(byte) method, 667

Write(byte[], int, int) method, 652, 667 Write(byte[]) method, 667 WriteByte(byte) method, 652 Write(char) method, 667, 844 Write(char[], int, int) method, 667 Write(char[]) method, 667 Write(decimal) method, 667 Write(double) method, 667 Write(int) method, 667, 844 WriteLine( ) method, 39, 338, 670, 844,

1210–1211 WriteLine(bool) method, 670, 844 WriteLine(char) method, 670, 844 WriteLine(char[]) method, 670 WriteLine(decimal) method, 670 WriteLine(double) method, 670 WriteLineIf methods, 1210–1211 WriteLineIf(bool, object) method, 1209 WriteLineIf(bool, object, string) method,

1210 WriteLineIf(bool, string) method, 1209 WriteLineIf(bool, string, string) method,

1210 WriteLine(int) method, 844 WriteLine(Int32) method, 670 WriteLine(Int64) method, 670 WriteLine(object) method, 670, 1210 WriteLine(string, object) method, 671, 1210 WriteLine(string, string) method, 1210 WriteLine(string) method, 670, 1210 WriteLine(UInt32) method, 670 WriteLine(UInt64) method, 670 Write(long) method, 667 WriteObject method, 762 writers, 666–673

System.IO.File class, 642 writing binary data, 667–669 writing textual data, 670–673

Write(sbyte) method, 667 Write(short) method, 667 Write(string) method, 667 WriteTo(Stream) method, 658 Write(uint) method, 667 Write(ulong) method, 667 Write(ushort) method, 667 writing

assertion contracts, 1224–1225 binary data, 667–669 to console, 843–845 invariant contracts, 1225–1226 postcondition contracts, 1223–1224

� INDEX

1282

writing (cont.) precondition contracts, 1222–1223 to streams, 654–655 textual data, 670–673

� X X component, 513 x parameter, 250–251, 335 x variable, 39, 47, 93, 124 XAttribute class, 931 XCData class, 931 XComment class, 931 XDeclaration class, 931–932 XDocument, populating with IEnumerable,

933–934 XDocument class, 931–932, 934 XDocument.ToString method, 933 XDocumentType class, 932 XElement, populating with IEnumerable,

933–934 XElement Add method, 941 XElement class, 926, 931, 934, 936–937, 947 XElement constructor, 927, 952 XElement.Add method, 952 XElement.Remove method, 941 XElements, creating using arbitrary types,

928–930 XML (Extensible Markup Language)

adding elements to, 950–952 creating

from CSV data, 953–954 CSV files from, 952–953 declaratively, 926–933 from LINQ queries, 946–949 objects from, 949–950 other node types, 930–931 valid documents, 932–933

grouping, 958–960 loading, 936 modifying, 940–944 modifying and transforming data, 950–

956 adding elements to XML, 950–952 changing and deleting elements,

955–956

creating CSV files from XML, 952–953

creating XML from CSV data, 953–954

processing declaratively, 936–940 filtering elements by name, 938–

939 finding all descendants, 939–940

querying for data, 945 reading and writing files, 934–936

loading XML, 936 saving XML, 934–936

saving, 934–936 serialization, 755–760

changing name for elements and attributes, 759–760

mapping members to elements and attributes, 758

selected fields only, 757 sorting, 957–958 using PLINQ to process, 960

xml type, 976 XmlAttribute attribute, 758–760 XmlElement attribute, 759–760 XmlIgnore attribute, 757 XmlSerializer class, 755, 757–759 XName class, 938 XText class, 931

� Y y parameter, 249, 251, 335 Y specifier, DateTime, 730 y variable, 47 Year property, DateTime, 726 yield break statement, 292–293 yield keyword, 86–87, 292–293, 296 yield return statements, 292, 294–295 yield statements, multiple, 294–295 yy format component, DateTime, 733 yyyy format component, DateTime, 733

� Z Zero property, 108