Programming C# 3.0
Programming C# 3.0, Fifth Edition By Jesse Liberty, Donald Xie
December 2007
Pages: 607

Cover | Table of Contents | Colophon


Index


[ Symbols ], 
[ A ], 
[ B ], 
[ C ], 
[ D ], 
[ E ], 
[ F ], 
[ G ], 
[ H ], 
[ I ], 
[ J ], 
[ K ], 
[ L ], 
[ M ], 
[ N ], 
[ O ], 
[ P ], 
[ Q ], 
[ R ], 
[ S ], 
[ T ], 
[ U ], 
[ V ], 
[ W ], 
[ X ], 


Symbols[ Top ]
+ (addition operator), 50
+= (addition self-assignment operator), 52
& (address-of operator), 554
&& (and operator) in conditionals, 55, 57
<> (angle brackets), around XML tags, 303
<% ... %> (angle brackets, percent sign), in ASP.NET, 388
= (assignment operator), 49
      confusing with equals operator, 39
      using instead of subscribe operator, 265
@ (at sign)
      beginning string literal, 215
      in XPath, 318, 320
\ (backslash)
      escape character for, 24
      in string literals, 24, 215
{} (braces)
      around statement blocks, 37
      in array element initialization, 162, 167
      in class declarations, 8, 62, 63
[] (brackets)
      in array declarations, 157, 165, 168
      in indexers, 176
      in metadata attributes, 450
      in syntax, 35
: (colon), in base class constructor invocation, 105
+ (concatenation operator), 220
-- (decrement operator), 53
* (dereference operator), 554
/ (division operator), 50
/= (division self-assignment operator), 52
. (dot operator), 11, 12
" (double quotes)
      escape character for, 24
      in string literals, 216
= (equal sign), in ASP.NET, 388
== (equals operator), 54
      confusing with assignment operator, 39
      overloading, requirements for, 119, 123
      with strings, 221
> (greater than operator), 54
>= (greater than or equals operator), 54
++ (increment operator), 53
[] (index operator)
      for arrays, 159
      for strings, 221
=> (lambda operator), 271
< (less than operator), 54
<= (less than or equals operator), 54
& (logical AND operator), 57
| (logical OR operator), 57
^ (logical XOR operator), 57
-> (member access operator), 554
% (modulus operator), 50
%= (modulus self-assignment operator), 52
* (multiplication operator), 50
*= (multiplication self-assignment operator), 52
!= (not equals operator), 54
! (not operator) in conditionals, 55
|| (or operator) in conditionals, 55, 57
() (parentheses)
      in if...else statement, 35
      in switch statement, 39
+ (plus sign), in debugger, 19
# (pound sign), preceding directives, 59
; (semicolon)
      ending statements, 33
      not ending class definitions, 63
<<>> (shift operator), 57
' (single quotes), escape character for, 24
/ (slash), in XPath, 318
/* ... */ (slash asterisk), enclosing comments, 10
// (slash, double), preceding comments, 9
+= (subscribe operator), 264, 265
- (subtraction operator), 50
-= (subtraction self-assignment operator), 52
?: (ternary operator), 58
-= (unsubscribe operator), 266

A[ Top ]
abstract classes, 108-111, 145
abstract keyword, 108
abstract modifier, 561
AcceptSocket() method, TcpListener, 512, 513
access modifiers, 106
      for classes, 65
      for properties, 94
      not allowed in explicit implementations, 151
ActiveX controls
      adding to form after importing, 548
      creating, 542-546
      importing, 542-550
Add() method
      Dictionary, 211
      List, 194, 195
      XmlAttributeOverrides, 335
addition operator (+), 50
addition self-assignment operator (+=), 52
AddRange() method, List, 194
address-of operator (&), 554
AddSort() method, XPathExpression, 328
ADO, compared to ADO.NET, 369
ADO.NET, 368
      compared to ADO, 369
      connecting to database, 374, 377
      disconnected architecture of, 368
      object model of, 372-374
      querying data, 375, 377
Adventure Works LT sample database, 338
AJAX, 6
      (see also Silverlight)
alert, escape character for, 24
and operator (&&) in conditionals, 55, 57
angle brackets (<>), around XML tags, 303
angle brackets, percent sign (<% ... %>), in ASP.NET, 388
animation, WPF, 409-412
anonymous class, 291
anonymous methods, 257, 270
anonymous types, 291
Append() method, StringBuilder, 226
AppendChild() method, XML, 308
AppendFormat() method, StringBuilder, 226, 227
AppendText() method
      File, 492
      FileInfo, 493
applications
      console applications, 11
      web-based (see web-based applications)
      Windows Forms (see Windows Forms applications)
      WPF applications (see WPF)
arguments of methods (see parameters of methods)
arithmetical operators, 50
arrays, 155
      as object of type System.Array, 156
      collections accessed as (see indexers)
      conversions of, 172-174
      declaring, 157
      default values for, 158
      elements of
            accessing, 159-160
            initializing, 162
      instantiating, 157
      iterating over, 161, 163
      jagged, 168-171
      methods for, 156
      multidimensional, 164-171
      passing as parameter without creating, 163
      properties for, 156
      rectangular, 164-168
      sorting, 174-176
      upper and lower bounds of, 158, 159, 171
as operator, 145
ASP (web) controls, 391
asp tag, 389
ASP.NET, 381
      books about, 381
      debugging, enabling, 388
      (see also Web Forms)
.aspx file extension, 382
AsReadOnly() method
      List, 194
      System.Array, 156
assemblies, 5
assignment
      definite, 27, 84
      operator precedence for, 57
assignment operator (=), 49
      confusing with equals operator, 39
      using instead of subscribe operator, 265
AsyncCallback delegate, 272-275, 507, 523
AsynchNetworkServe class, 518
asynchronous I/O, 487, 506-511
asynchronous network file streaming, 522-527
at sign (@)
      beginning string literal, 215
      in XPath, 318, 320
Attributes property, DirectoryInfo, 488
Attributes() method, FileInfo, 493
attributes, in metadata, 449
      accessing (see reflection)
      custom, 451-455
      naming conventions for, 452
      parameters of, 453
      targets of, 450
            applying to attributes, 450
            list of, 449
      types of, 450
attributes, of files, 488, 493
attributes, of XML elements, 309-311
AttributeTargets enumeration, 450
AutoComplete feature, fixing case errors with, 14
automatic properties, 94
axes, XPath searches using, 319
Aximp utility, 542, 547, 548

B[ Top ]
backing store, 487
backslash (\)
      escape character for, 24
      in string literals, 24, 215
backspace, escape character for, 24
base class constructors, 105
base classes, 100, 112
      (see also abstract classes)
base keyword, 105, 561
BeginRead() method, Stream, 506, 508
BeginWrite() method, Stream, 506
Berkeley socket interface, 513
binary files, 500-502
BinaryFormatter class, 530
BinaryReader class, 499
BinarySearch() method
      List, 194
      System.Array, 156
BinaryWriter class, 499
binding
      late binding, using reflection, 456, 462-464
      server-side controls to data, 391-398
books
      Learning ASP.NET 2.0 with AJAX (Liberty et al.), 381
      Programming .NET 3.5 (Liberty, Horovitz), x, 6, 405
      Programming ASP.NET (Liberty, Hurwitz), 381, 401
      Programming Silverlight (Liberty), 6
      Programming WCF Services (Lowy), 329
      Programming WPF (Sells, Griffiths), 405
      Swann's Way (Proust), 557
bool type, 22
boolean type, 22
braces ({})
      around statement blocks, 37
      in array element initialization, 162, 167
      in class declarations, 8, 62, 63
brackets ([])
      in array declarations, 157, 165, 168
      in indexers, 176
      in metadata attributes, 450
      in syntax, 35
      (see also index operator ([]))
branching
      conditional branching statements, 35-42
      unconditional branching statements, 34
      (see also jump statements)
break statement
      in loops, 47
      in switch statement, 39, 41
breakpoints, in debugger, 18
buffered streams, 502-504
BufferedStream class, 499, 502
bugs, compared to exceptions, 240
built-in types, 21, 22-25
      choosing, 23
      conversion of, 24
      list of, 22
button controls, Windows Forms, 432-437
byte type, 22

C[ Top ]
C
      strings, differences in, 213
      switch statement differences, 41
C#, x, 3
      book about, x
      features of, 4-6
      history of, 4
      invoking unmanaged code from, 551-554
      new features in, 3, 4
C++
      indexer operator, overloading, equivalent to, 177
      multiple inheritance, equivalent for, 100
      nonstatic operators, no equivalent for, 118
      object types that can be thrown, limitations to, 241
      private and protected inheritance, no equivalent for, 100
      structs, differences in, 126
      switch statement differences, 41
      templates, equivalent for, 185
C++-style comments, 9
call stack
      displaying, with stack trace, 252-254
      unwinding, 241, 245
callback methods, 271-275
camel notation, 14
Capacity property, List, 194, 196
capture collections, for regular expressions, 236-239
Capture object, 236
CaptureCollection collection, 236
carriage return, escape character for, 24
case sensitivity, 14
case statement (see switch statement)
casting (explicit conversions), 25, 120, 123
catch block, 243, 245
catch statement, 240, 243-249
char keyword, 562
char literals, 24
      (see also string literals)
char type, 22, 24
      (see also strings)
Chars property
      String, 217
      StringBuilder, 226
checked keyword, 562
child elements, XML, 303, 308
class keyword, 62, 562
classes, 4, 8, 61
      abstract classes, 108-111, 145
      access modifiers for, 65
      anonymous, 291
      base classes, 100, 112
      behaviors of (see methods)
      concrete classes, 110
      declarations of, 4, 8
      defining, 62-65
      derived classes, 100, 112
      generated, adding methods to, 348
      metadata stored with, 5
      named by Visual Studio, 16
      naming conventions for, 14
      nesting, 114-116
      partial classes, 382
      sealed classes, 111
      tracking instances of, 77
Clear() method
      Dictionary, 211
      List, 194
      Queue, 205
      Stack, 207
      System.Array, 156
ClientHandler class, 518, 523
Clone() method, System.Array, 156
Close() method, 80
code examples, xvi
code reuse, inheritance used for, 101
code separation, 382
code style guidelines by Microsoft, 14
code, commenting out, 10
code-behind pages, 381, 386-388
collection interfaces, 185
      IComparable interface, 197-200
      IComparer interface, 200-204
      IEnumerable interface, 186-188
      list of, 185
      type safety of, 185
collections, 155
      accessing as arrays (see indexers)
      dictionaries, 210-212
      hash function for, 112
      Item element for, 195
      queues, 205-207
      stacks, 207-210
      type safety of, 155
      (see also arrays; lists)
colon (:), in base class constructor invocation, 105
columns, relational database, 369
COM components (see ActiveX controls)
comments, 9
      around code, 10
      author's guidelines for, 317
      for XML-based documentation, 11
      nesting, 10
Compare() method, String, 217, 220
CompareTo() method
      IComparable, 197
      String, 217
comparison operators (see relational operators)
Compile() method, XPathNavigator, 328
compiling programs, 17
component-oriented programming, with C#, 5
Concat() method, String, 217, 220
concatenation operator (+), 220
concrete classes, 110
conditional branching statements, 35-42
      Boolean expressions required for, 35
      if...else statement, 35-37
      nested if statements, 37
      switch statement, 38-42
conditional directives, 60
console applications, 11
Console object, 11
const keyword, 562
constants, 28
      naming conventions for, 14
      (see also enumerations)
ConstrainedCopy() method, System.Array, 156
constraints
      for lists, 189-194
      for relational database, 370
constructors, 68-71
      base class constructors, 105
      default, 68
      defining, 69
      overloading, 71, 75, 87-90
contact information for this book, xvi
Contains() method
      List, 194
      Queue, 205
      Stack, 207
ContainsKey() method, Dictionary, 211
ContainsValue() method, Dictionary, 211
continue keyword, 562
continue statement, 47
controls, ActiveX (see ActiveX controls)
controls, server-side (see server-side controls)
controls, Windows Forms
      button controls, 432-437
      creating, 421
      populating, 424-428
      TreeView controls, 424-432
conventions used in this book, xiv
conversions (see type conversion)
ConvertAll() method
      List, 194
      System.Array, 156
Copy() method
      File, 492
      String, 217, 221
      System.Array, 156
CopyTo() method
      FileInfo, 493, 497
      List, 194
      Queue, 205
      Stack, 207, 208, 210
      String, 217
      System.Array, 156
corruption of databases, 343
Count property
      Dictionary, 211
      List, 194
      Queue, 205
      Stack, 207
Create() method
      DirectoryInfo, 489
      File, 492
      FileInfo, 493
CreateAttribute() method, XML, 309
CreateChildControls() method, 385
CreateDirectory() method, Directory, 488
CreateElement() method, XML, 307
CreateInstance() method, System.Array, 156, 171
CreateNavigator() method, XmlDocument, 326
CreateSubdirectory() method, DirectoryInfo, 489, 496
CreateText() method, File, 492
CreationTime property
      DirectoryInfo, 488
      FileInfo, 493
C-style comments, 10
curly braces (see braces)

D[ Top ]
data binding, 391-398
data compartment for application, 538
data store, 538
DataAdapter class, ADO.NET, 373, 374, 377
databases, 368
      Adventure Works LT sample database, 338
      connecting to, with ADO.NET, 374, 377
      connecting to, with LINQ (see LINQ)
      corruption of, 343
      relational databases, 368-371
      searching
            LINQ for (see LINQ)
            methodologies for, 279
DataColumn class, ADO.NET, 373
DataColumnCollection class, ADO.NET, 373
DataContext object, 342, 345, 348, 350
DataReader class, ADO.NET, 374
DataRelation class, ADO.NET, 373
DataRelationCollection class, ADO.NET, 373
DataSet class, ADO.NET, 372, 375, 377
DataTable class, ADO.NET, 373, 377
DBCommand class, ADO.NET, 374
DBConnection class, ADO.NET, 374
deadlocks, 485
debugger, Visual Studio, 18-20
      breakpoints in, 18
      examining object values, 19
      stepping through program, 19
debugging, ASP.NET, 388
decimal keyword, 562
decimal type, 22, 23
declarative pinning, 556
declarative referential integrity (DRI), 370
decrement operator (--), 53
decrement operators, 52-53
default keyword, 562
#define directive, 59
definite assignment, 27, 84
delegate keyword, 256, 562
delegates, 5, 256
      asynchronous I/O, 507
      callbacks using, 271-275
      creating, 256
      methods called directly, preventing, 265-270
      potential problems with, 265
      publish and subscribe pattern using, 257-265
      uses of, 256
Delete() method
      DirectoryInfo, 489
      File, 492
      FileInfo, 493
Dequeue() method, Queue, 205
dereference operator (*), 554
derived classes, 100, 112
deserialization, 532-534
Deserialize() method, XmlSerializer, 331
destructors
      Finalize() implemented using, 112
      structs not allowing, 128
dictionaries, 210-212
Dictionary class, 211
directives, preprocessor, 59-60
directories, 488
      listing files in, 492-496
      traversing subdirectories of, 489-492
Directory class, 488, 499
Directory property, FileInfo, 493
DirectoryInfo class, 488, 499
      instantiating, 489
      methods of, 488
      properties of, 488
      subdirectories
            returning files for, 492
            traversing, 489-492
Dispose() method, IDisposable, 79, 80, 385
division operator (/), 50
division self-assignment operator (/=), 52
do...while loop, 44
document element (see root element, XML)
documentation
      this keyword used as, 75
      (see also comments)
DocumentElement property, XML, 308
dot operator (.), 11, 12
double keyword, 562
double quotes (")
      escape character for, 24
      in string literals, 216
double type, 22, 23
DRI (declarative referential integrity), 370
dynamic invocation (see late binding, using reflection)
dynamic strings (see StringBuilder class)

E[ Top ]
elements, XML
      attributes of, 309-311
      defining, 303
#elif directive, 60
#else directive, 60
else statement (see if...else statement)
Empty property, String, 217
encapsulation, 61
#endif directive, 60
EndRead(), method, Stream, 509
EndsWith() method, String, 217, 221
Enqueue() method, Queue, 205
enumerations, 30-31
equal sign (=), in ASP.NET, 388
      (see also assignment operator (=))
equals operator (==), 54
      confusing with assignment operator, 39
      overloading, requirements for, 119, 123
      with strings, 221
Equals() method
      Object, 112, 119, 124
      String, 217, 221
errors, compared to exceptions, 240
escape characters, 24, 215
event handlers, 257
      Web Forms, 382, 383
      Windows Forms, 423, 429-437
      WPF applications, 418
event keyword, 266-270
EventArgs class, 257
events, 255
      observing of, 257
      publishing of, 257, 261-263
      subscribing to, 257, 263
      unsubscribing from, 266
      Web Forms, 383, 399-403
examples, source code for, xi
exception handler, 240
Exception objects, 251-254
exceptions, 240
      actions performed regardless of, 249-251
      catching, 240, 243-249
      throwing, 240, 241-243
Exists property
      DirectoryInfo, 488
      FileInfo, 493
Exists() method
      File, 492
      List, 194
      System.Array, 156
explicit conversions (casting), 25, 120, 123
explicit interface implementation, 150-153
expressions, 49
eXtensible Markup Language (see XML)
extension methods, LINQ, 3, 292-294, 351
      defining and using, 294-296
      multiple implementations of, on different targets, 301
      queries using, as method-based queries, 298
      restrictions on, 296
Extension property
      DirectoryInfo, 488
      FileInfo, 493
extern keyword, 563
extra whitespace, 33

F[ Top ]
"f" suffix on a number, 24
FIFO (first-in, first-out) collection (see queues)
File class, 488, 499
      methods for, 492
      relationship to FileInfo class, 492
FileInfo class, 496, 499
      methods for, 493
      properties for, 493
      relationship to File class, 492
files
      accessing in Vista, exceptions caused by, 492, 496
      asynchronous I/O for (see asynchronous I/O)
      binary files, 500-502
      listing for subdirectories, 492-496
      modifying, 496-499
      reading and writing (see streaming)
      text files, 504-506
FileStream class, 499
FileSystemInfo class, 488
filter, of query, 282
Finalize() method, Object, 112
finalizers, 78
finally block, 241, 249-251
finally keyword, 563
finally statement, 249-251
Find() method
      List, 194
      System.Array, 156
FindAll() method
      List, 194
      System.Array, 156
FindIndex() method
      List, 194
      System.Array, 156
FindLast() method
      List, 194
      System.Array, 156
FindLastIndex() method
      List, 195
      System.Array, 156
first-in, first-out (FIFO) collection (see queues)
fixed keyword, 556
float type, 22, 23
folders (see directories)
fonts used in this book, xiv
for keyword, 563
for loop, 44-47
foreach keyword, 563
foreach loop, 161, 163
ForEach() method
      List, 195
      System.Array, 156
foreign key, relational database, 370
form feed, escape character for, 24
Format() method, String, 217
formatter for serialization, 530
forms (see Web Forms; Windows Forms applications controls)
forward slash (see slash)
from clause of query, 282
FullName property
      DirectoryInfo, 488
      FileInfo, 493
functions, C# (see methods)
functions, XPath, 321

G[ Top ]
garbage collection, 23, 78
generalization, 97-100
generic collection interfaces (see collection interfaces)
generics, 185
get accessors, 93
get keyword, 563
get() method, for indexers, 179
GetAttributes() method, File, 492
GetCreationTime() method
      Directory, 488
      File, 492
GetDirectories() method
      Directory, 488, 492
      DirectoryInfo, 489
GetEnumerator() method
      Dictionary, 211
      List, 195
      Queue, 205
      Stack, 207
      System.Array, 156
GetFiles() method
      Directory, 488
      DirectoryInfo, 489, 492
GetFileSystemInfos() method, DirectoryInfo, 489
GetHashCode() method, Object, 112
GetLastAccessTime() method, File, 492
GetLastWriteTime() method, File, 493
GetLength() method, System.Array, 156
GetLogicalDrives() method, Directory, 488
GetLongLength() method, System.Array, 156
GetLowerBound() method, System.Array, 156
GetObjectData() method, Dictionary, 211
GetParent() method, Directory, 488
GetProperties() method, XmlAttributeOverrides, 335
GetRange() method, List, 195
GetResponse(), WebRequest, 527
GetResponseStream() method, WebResponse, 527
GetType() method
      Object, 112
      XmlSerializer, 330
GetUpperBound() method, System.Array, 156
GetValue() method, System.Array, 156
"goes to" operator (see lambda operator)
goto keyword, 564
goto statement, 42
      in switch statement, 39, 41
      reasons to avoid, 42
graphical user interface (see GUI)
greater than operator (>), 54
greater than or equals operator (>=), 54
grids, WPF, 406-408
Griffiths, Ian
      blog for, 301
      Programming WPF, 405
Group class, 233
grouping in query, 290
Groups collection, 233
groups, regular expressions, 233-236
GUI (graphical user interface)
      programs without (see console applications)

H[ Top ]
HasAttributes property, XmlElement, 319
hash function for collections, 112
heap, 23
Hejlsberg, Anders (C# creator), 4
"Hello World" example, 7, 14-18
HelpLink property, Exception, 252
HKEY_CURRENT_USER key, 538
Horovitz, Alex (Programming .NET 3.5), x, 6, 405
HTML controls, 391
HttpWebRequest class, 527
Hungarian notation, 32
Hurwitz, Dan (Programming ASP.NET), 381, 401

I[ Top ]
IAsyncResult interface, 507
ICollection interface, 185, 186
IComparable interface, 186, 197-200
IComparer interface, 186, 200-204
identifiers (names), 32
      (see also naming conventions)
identifiers, preprocessor, 59
IDeserializationCallback interface, 535
IDictionary interface, 186, 211
IEnumerable interface, 186-188
IEnumerator interface, 185
#if directive, 60
if...else statement, 35-37
IFormatter interface, 530
IList interface, 186
implicit conversions, 24, 120, 123
implicit types, 22
implicitly typed local variables, 291
increment operator (++), 53
increment operators, 52-53
index operator ([])
      for arrays, 159
      for strings, 221
indexers, 176-180
      assignment to, 180-182
      based on strings, 182-185
      declaring, 176
      get() and set() methods for, 179
IndexOf() method
      List, 195
      String, 222
      System.Array, 156
information
      contact information for this book, xvi
      (see also books; web site resources)
inheritance, 97, 100
.ini files, 538
Initialize() method, System.Array, 157
initializers, 71-73
inline documentation, 5
inner join, SQL, 372
Insert() method
      List, 195
      String, 222
      StringBuilder, 226
InsertRange() method, List, 195
instance members of a class, 76
instances (see objects)
int keyword, 564
int type, 22, 23
int16 type, 22
int32 type, 22
int64 type, 23
interface keyword, 131
interfaces, 5, 131
      combining, 136-139
      compared to abstract classes, 145
      defining, 131-133
      extending, 135
      hiding members of, 153
      implementing, 133-135
            explicitly, 150-153
            multiple interfaces, 135
      naming, 132
      overriding, 146-150
      polymorphism and, potential problems with, 139-145
Interlocked class, 477
internal access modifier, 66, 94
IP address, 512
is-a relationship (see specialization)
IsFixedSize property, System.Array, 157
isolated storage, 538-541
IsolatedStorageFileStream object, 538
IsReadOnly property, System.Array, 157
IsSynchronized property, System.Array, 157
Item element for collection classes, 195
Item property, IDictionary, 211
Item() method
      Dictionary, 211
      List, 194
iteration statements, 42-49
      do...while loop, 44
      for loop, 44-47
      foreach loop, 161, 163
      while loop, 43

J[ Top ]
jagged arrays, 168-171
Java
      constant fields, no equivalent for, 131
      final class, equivalent for, 111
join clause of query, 285
Join() method
      LINQ, 301
      String, 217
jump statements
      break statement, 47
      continue statement, 47
      goto statement, 42
      in switch statement, 39, 41
      return statement, 35, 125
      (see also unconditional branching statements), 35

K[ Top ]
keyboard shortcuts, 17
Keys property, Dictionary, 211
keywords
      reference, 561-568

L[ Top ]
lambda expressions
      for delegate definitions, 270
      in LINQ, 297-301
lambda operator (=>), 271
Language-INtegrated Query (see LINQ)
LastAccessTime property
      DirectoryInfo, 488
      FileInfo, 493
last-in, first-out (LIFO) collections (see stacks)
LastIndexOf() method
      List, 195
      System.Array, 157
LastWriteTime property
      DirectoryInfo, 489
      FileInfo, 493
late binding, using reflection, 456, 462-464
Learning ASP.NET 2.0 with AJAX (Liberty et al.), 381
Length property
      FileInfo, 493
      String, 217, 221
      StringBuilder, 226
      System.Array, 157, 159
less than operator (<), 54
less than or equals operator (<=), 54
Liberty, Jesse (author), x
      Learning ASP.NET 2.0 with AJAX, 381
      Programming .NET 3.5, x, 6, 405
      Programming ASP.NET, 381, 401
      Programming Silverlight, 6
      support provided by, xv
      web site for, xi
life cycle, Web Forms, 384
LIFO (last-in, first-out) collections (see stacks)
line break, in string literals, 215
LINQ (Language-INtegrated Query), 279
      compared to SQL, 285
      connecting to SQL database, 339
      deleting data, 358-362
      extension methods of, 3, 285, 292-297, 298, 301, 351
      lambda expressions in, 297-301
      mapping class properties to database columns
            manually, 340-343
            with Visual Studio, 344-348
      queries
            caching results of, 284
            creating, 280-283, 352
            deferred execution of, 283
      retrieving data, 349-353
      table properties, creating, 350
      updating data, 353-358
      XML output from, 363-367
List class, 194
lists, 194
      adding items to, 195
      capacity of, 196
      constraints for, 189-194
      methods for, 194
      properties for, 194
literal values, 50
literals, 28
      char literals, 24
      string literals, 32, 215
Load event, 385
LoadPostData() method, 384
LoadViewState() method, 384
lock statement, 479
locking resources (see synchronization)
logical AND operator (&), 57
logical operators, 55, 57
logical OR operator (|), 57
logical XOR operator (^), 57
long type, 23
LongLength property, System.Array, 157
loop variable, scope of, 46
loops (see iteration statements)
Lowy, Juval (Programming WCF Services), 329

M[ Top ]
"m" suffix on a number, 24
Main() method, 8
manifest types, 22
Match objects, 231-233
MatchCollection type, 231-233
mathematical operators, 50
member access operator (->), 554
member variables
      readonly, 95
      static, 77
      (see also properties)
members of a class, 62
      (see also events; indexers; methods; properties; variables)
MemberwiseClone() method, Object, 112
MemoryStream class, 500
Message property, Exception, 251
metadata, 5, 449
      attributes of (see attributes, in metadata)
      reading (see reflection)
method-based queries, 298
methods, 8, 62
      adding to generated classes, 348
      anonymous, 257, 270
      callback methods, 271-275
      declarations of, 8, 65
      encapsulated in delegates (see delegates)
      for arrays, 156
      invoking
            as unconditional branching, 34
            with dot operator, 11
      LINQ extension methods (see extension methods, LINQ)
      naming conventions for, 8, 14
      overloading, 87-90
      overriding, 101-105, 146-150
      parameters of, 8, 9, 66-68, 81-87
      polymorphic, 101-105
      return value of, 8, 9
            multiple values, 9
            void, 9
      selectively exposing in interface, 152
      signature of, 87
      stack frame allocated for, 23
      static
            accessing member variables using, 78
            invoking, 76, 77
            passing instance members to, 76
      with same signature, in two implemented interfaces, 150
Microsoft code style guidelines, 14
modulus operator (%), 50
modulus self-assignment operator (%=), 52
monitors, 480-485
Move() method
      Directory, 488
      File, 493
MoveNext() method, XPathNodeIterator, 327
MoveTo() method
      DirectoryInfo, 489
      FileInfo, 493
multidimensional arrays, 164-171
multiplication operator (*), 50
multiplication self-assignment operator (*=), 52

N[ Top ]
\n escape character, in string literal, 215
Name property
      DirectoryInfo, 489
      FileInfo, 493
Named Pipes protocol, enabling, 338
names (identifiers), 32
      (see also naming conventions)
namespaces, 11
      dot operator for, 12
      naming conventions for, 14
      using directive for, 13
      (see also specific namespaces)
naming conventions, 14, 32, 452
nested classes, 114-116
nested comments, 10
nested if statements, 37
.NET platform, 6
      book about, 6
      new features in, 6
network I/O, 511-513
      asynchronous network file streaming, 522-527
      multiple connections, handling, 518-522
      streaming network client for, 515-518
      streaming network server for, 513-515
      testing on single machine, 518
NetworkStream class, 500, 513
new keyword
      for array instantiation, 157
      for methods not overridden, 107
      for object instantiation, 68
new operator, 565
newlines
      escape character for, 24
      in string literals, 215
      (see also whitespace)
nonpostback events, Web Forms, 383
NonSerialized attribute, 535
normalization, relational database, 370
Northwind database, 369
not equals operator (!=), 54
not operator (!) in conditionals, 55
null keyword, 565
null, escape character for, 24

O[ Top ]
object graph, 529
object initializers, 73, 291
Object type, 112-114
object type, 565
object-oriented languages, C# as, 4
objects, 8, 61, 63
      as reference and value types, 129
      as reference types, 23
      copying, 112
      created by instantiation, 63, 68-71
      destroying, 78-81
      equivalence of, determining, 112
      on the heap, 23
      passing as parameters, 75
      referring to same instance, determining, 112
      string representation of, 112
      tracking number of instances, 77
observer design pattern, 257
OCX standard, 542
OnDeserialization() method, IDeserializationCallback, 535
OnLoad() method, 385
OnPreRender() method, 385
OnReadComplete() method, ClientHandler, 518, 521
OnWriteComplete() method, ClientHandler, 518, 521
Open() method, FileInfo, 493
OpenRead() method
      File, 493, 500
      FileInfo, 493
OpenText() method, FileInfo, 493, 504
OpenWrite() method
      File, 493, 500
      FileInfo, 493
operator keyword, 117, 565
operators, 49
      arithmetical operators, 50
      assignment operator (=), 49
      decrement operators, 52-53
      increment operators, 52-53
      logical operators, 55
      mathematical operators, 50
      overloading, 117
            alternatives for other languages, 118
            cautions regarding, 119
            examples of, 123
            required pairs of, 119
      postfix operators, 53
      precedence of, 55-58
      prefix operators, 53
      relational operators, 54
      self-assignment operators, 52
      short-circuit evaluation of, 56
      ternary operator, 58
      (see also specific operators)
or operator (||) in conditionals, 55, 57
orderby clause of query, 286-289, 301
OrderBy() method, LINQ, 301
out keyword, 565
out parameters, 84-87
outer join, SQL, 372
overloaded constructors, 71, 75, 87-90
overloaded methods, 87-90
override keyword, 101, 106, 565
overriding Equals() method, 119
overriding interface implementations, 146-150
overriding methods, 101-105

P[ Top ]
P/Invoke (platform invoke facility), 551-554
parameters of methods, 8, 9, 81-87
      defining, 66-68
      optional, 67
      out parameters, 84-87
      passing by reference, 9, 82-84
      passing by value, 9, 81
      with same name as member variable, 74
params keyword, 163, 565
parent elements, XML, 303
Parent property, DirectoryInfo, 489
parentheses (())
      in if...else statement, 35
      in switch statement, 39
partial classes, 382
partial keyword, 348, 565
Pascal notation, 14
passing by reference, 9
passing by value, 9
Peek() method
      Queue, 205, 207
      Stack, 207, 208
platform invoke facility (P/Invoke), 551-554
plus sign (+), in debugger, 19
      (see also addition operator (+))
pointer operators, 554
pointers, 5, 554-560
      avoiding, 6
      compared to this keyword, 74
polymorphism, 97, 101
      base class constructors, calling, 105
      polymorphic methods, 101-105
      polymorphic types, 101
Pop() method, Stack, 207, 208
ports, 512
postback events, Web Forms, 383
postfix operators, 53
pound sign (#), preceding directives, 59
precedence of operator evaluation, 55-58
predicates (search conditions), XPath, 318, 320-321
prefix operators, 53
preprocessor directives, 59-60
preprocessor identifiers, 59, 60
primary key, relational database, 369
private access modifier, 66, 94, 565
Programming .NET 3.5 (Liberty, Horovitz), x, 6, 405
Programming ASP.NET (Liberty, Hurwitz), 381, 401
Programming Silverlight (Liberty), 6
Programming WCF Services (Lowy), 329
Programming WPF (Sells, Griffiths), 405
programs
      compiling and running, 17
      creating, 15
Project Gutenberg, 557
projection of query, 283, 294
properties, 62, 90-93
      access modifiers for, 94
      automatic properties, 94
      declaring, 92
      for arrays, 156
      get accessors for, 93
      mapping to database columns
            manually, 340-343
            with Visual Studio, 344-348
      naming conventions for, 14
      readonly fields, 95
      set accessors for, 93
protected access modifier, 66, 94, 565
protected internal access modifier, 66
public access modifier, 66, 566
publish and subscribe design pattern, 257-265
publishing events, 257, 261-263
Push() method, Stack, 207, 208

Q[ Top ]
queries, ADO.NET, 375, 377
queries, LINQ
      caching results of, 284
      creating, 280-283, 352
      deferred execution of, 283
      from clause, 282
      grouping, 290
      join clause, 285
      method-based queries, 298
      orderby clause, 286-289
      range variable for, 282
      select clause (projection), 283, 294
      storing results with anonymous types, 291
      where clause (filter), 282
queries, SQL, 371
Queue class, 205
queues, 205-207
quotes (see double quotes; single quotes)

R[ Top ]
race conditions, 485
RAD (Rapid Application Development)
      Web Forms for, 381
RaisePostDataChangedEvent() method, 385
range variable, LINQ, 282
Rank property, System.Array, 157
Rapid Application Development (RAD)
      Web Forms for, 381
Read() method, Stream, 500
Reader class, ADO.NET, 368
ReadLine() method
      Console, 47
      StreamReader, 504
readonly fields, 95
readonly modifier, 566
records, relational database, 369
rectangular arrays, 164-168
ref keyword, 83
ref modifier, 566
reference types, objects as, 23, 129
ReferenceEquals() method, Object, 112
reflection, 449, 456
      creating types at runtime using, 456
      late binding using, 456, 462-464
      type discovery using, 456, 458-462
      viewing metadata using, 456-457
reflection emit (see types, creating at runtime using reflection)
Refresh() method, DirectoryInfo, 489
Regex class, 229
Regsvr32 utility, 546
regular expressions, 213, 228-231
      capture collections for, 236-239
      grouping subexpression matches of, 233-236
      match collections for, 231-233
relational databases, 368-371
      constraints, 370
      declarative referential integrity (DRI), 370
      normalization of, 370
      querying with SQL, 371
relational operators, 54
      operator precedence for, 57
      overloading, required pairs for, 119
remainders in division (see modulus operator (%))
Remove() method
      Dictionary, 211
      List, 195
      StringBuilder, 226
RemoveAll() method, List, 195
RemoveAt() method, List, 195
RemoveRange() method, List, 195
Render() method, 385
Replace() method, StringBuilder, 226
Resize() method, System.Array, 157
resources
      locking (see synchronization)
      unmanaged, cleaning up, 112
resources (information)
      contact information for this book, xvi
      (see also books; web site resources)
return statement, 35, 125
return value of methods, 8
Reverse() method
      List, 195
      System.Array, 157, 174
root element, XML, 303, 307
Root property, DirectoryInfo, 489
Rows collection, ADO.NET, 373
rows, relational database, 369
runat=Server attribute, 391

S[ Top ]
SaveViewState() method, 385
sbyte keyword, 566
sbyte type, 22
screen scraping, 529
sealed classes, 111
sealed keyword, 111
sealed modifier, 566
search conditions (predicates), XPath, 318, 320-321
searching database (see LINQ)
security, with data binding, 398
select clause of query, 283, 294
Select() method, XPathNavigator, 327
SelectNodes() method, XPath, 321
SelectSingleNode() method, XPath, 318, 319, 326
self-assignment operators, 52
Sells, Chris (Programming WPF), 405
semicolon (;)
      ending statements, 33
      not ending class definitions, 63
Serializable attribute, 529, 531
serialization, 487, 529-538
      formatter for, 530
      transient data, handling, 535
serialization, XML, 329-331
      customizing using attributes, 331-333
      deserialization, 331
      runtime customization of, 333-336
Serialize() method, formatter, 532
server-side controls
      adding to Web Form, 388-391, 399-403
      ASP (web) controls, 391
      binding to data, 391-398
      HTML controls, 391
      validation controls, 401
set accessors, 93
set() method, for indexers, 179
SetAttributes() method, File, 492
SetCreationTime() method, File, 492
SetLastAccessTime() method, File, 492
SetLastWriteTime() method, File, 493
SetValue() method, System.Array, 157
shift operator (<<>>), 57
short type, 22
short-circuit evaluation, 56
signature of method, 87
Silverlight, information about, 6
Simonyi, Charles (inventor of Hungarian notation), 32
single quotes ('), escape character for, 24
single type, 22
slash (/), in XPath, 318
      (see also division operator (/))
slash asterisk (/* ... */), enclosing comments, 10
slash, double (//), preceding comments, 9
SOA, book about, 329
SOAP, 530
SoapFormatter class, 530
sockets, 511
software requirements, x
Sort() method
      List, 195, 197
      System.Array, 157, 174
sorting arrays, 174-176
sorting query results, 286-289
source code for examples, xi
spaces (see whitespace)
specialization, 97-100
Split() method
      Regex, 230
      String, 217, 225
SQL (Structured Query Language), 371
      connecting to database with LINQ (see LINQ)
      LINQ syntax compared to, 285
SQL injection attack, 398
SQL Server 2005 Adventure Works LT sample database, 338
SQL Server, version used for this book, x
SQML (Structured Query Markup Language), 304
square brackets (see brackets)
stack (in memory), 23
      (see also call stack)
Stack class, 207
stack frame, 23, 241
stack panels, WPF, 406-408, 414
stack trace, 252-254
stackalloc keyword, 566
stacks, 207-210
StackTrace property, Exception, 252
standard output, 11
Start() method, TcpListener, 512, 513
StartRead() method, ClientHandler, 518, 523
starts-with() function, XPath, 321
StartsWith() method, String, 217
state object, asynchronous I/O, 507
state of web application, 384
statement blocks, 37
statements, 33
      conditional branching statements, 35-42
      iteration statements, 42-49
      unconditional branching statements, 34
      (see also specific statements)
static keyword, 14, 76
static members of a class, 14, 76-78
      accessing, 76
      member variables, 77
      methods
            accessing member variables using, 78
            invoking, 76, 77
            passing instance members to, 76
static modifier, 566
statically typed, 21
storage, isolated, 538-541
Stream class, 499
streaming
      asynchronous network files, 522-527
      network client, 515-518
      network server, 513-515
      web streams, 527-529
StreamReader class, 504
streams, 487
      backing store for, 487
      buffered, 502-504
      serialization of data for (see serialization)
StreamWriter class, 504, 513
String class, 214
string keyword, 32
string literals, 32, 215
      (see also char literals)
string representation of object, 112
StringBuilder class, 226-227
StringReader class, 499
strings, 32, 214, 566
      comparing, 220
      concatenating, 220
      copying, 221
      creating with literals, 215
      creating with ToString() method, 216
      delimiters in, problems with, 228
      equality of, testing, 221
      finding specific character in, 221
      immutable (String class), 214
      indexers based on, 182-185
      length of, 221
      manipulating, 216-222
      methods and properties for, 216
      mutable (StringBuilder class), 226-227
      ordering, 214
      parsing into substrings, 225
      String type compared to string type, 214
      switch statement using, 42
      (see also regular expressions; substrings)
StringWriter class, 499
strongly typed, 22
structs, 5, 126, 566
      creating, 128-130
      defining, 127
      performance of, 126
Structured Query Markup Language (SQML), 304
style guidelines for code, by Microsoft, 14
styles, WPF, 409-412
subdirectories
      creating, 496
      listing files in, 492-496
      traversing, 489-492
subscribe operator (+=), 264, 265
subscribing to events, 257, 263
Substring() method, String, 217, 222-224
substrings
      finding at end of string, 221
      finding location of, within string, 222
      finding within string, 222-224
      inserting into a string, 222
      parsing string into, 225
subtraction operator (-), 50
subtraction self-assignment operator (-=), 52
support for this book, xv
Swann's Way (Proust), 557
switch keyword, 567
switch statement, 38-42
      C and C++ differences in, 41
      default case for, 41
      on strings, 42
      Visual Basic 6 equivalents to, 40
symbolic constants, 28
symbolic values, 50
synchronization, 465, 474-477
      Interlocked class for, 477
      lock statement for, 479
      monitors for, 480-485
      (see also thread synchronization)
synchronous I/O, 506
SyncRoot property, System.Array, 157
System.Array type, 156
System.Attribute class, 452
System.IO namespace, 488
System.Object type, 112-114
System.Reflection namespace, 451
System.Threading namespace, 465
System.Web namespace, 382
System.Web.Extension namespace, 382
System.Web.UI namespace, 382
System.Xml namespace, 307
System.Xml.Serialization namespace, 329
System.Xml.XPath namespace, 311, 322
SystemRoot directory, 496

T[ Top ]
\t escape character, in string literal, 215
tables, relational database, 369
tabs
      escape characters for, 24
      in string literals, 215
      (see also whitespace)
tags, XML, 303
targets, of metadata attributes, 450
      applying to attributes, 450
      list of, 449
TCP/IP protocol, 511
TcpClient class, 515
TcpListener object, 512, 513
ternary operator (?:), 58
text files, 504-506
TextReader class, 499
TextWriter class, 499
ThenBy() method, LINQ, 301
this keyword, 74-75
      as documentation, 75
      in indexer declarations, 176, 179
      to call overloaded constructors, 75
      to pass objects as parameters, 75
      to qualify instance members, 74
Thread class, 466
thread synchronization, 485
threads, 465
      creating, 466
      joining, 469
      killing, 470-474
      scheduling of, 469
      starting, 467
      suspending (sleeping), 469
      uses of, 466
ThreadStart delegate class, 466
throw statement, 241-243
ToArray() method
      LINQ, 284
      List, 195
      Queue, 205
      Stack, 208
ToArray() method, Stack, 208
ToList() method, LINQ, 284
ToString() method, Object, 112, 114, 124, 216
ToUpper() method, String, 217
TreeView controls, Windows Forms
      event handling for, 429-432
      populating, 424-428
Trim() method, String, 217
TrimEnd() method, String, 217
TrimExcess() method
      List, 195
      Queue, 205
      Stack, 208
TrimToSize() method, List, 195
TrueForAll() method, System.Array, 157
try block, 243, 245
TryGetValue() method, Dictionary, 211
type conversion
      implementing operators for, 120, 123
      of built-in types, 24
type discovery, using reflection, 456, 458-462
types, 7, 21
      built-in types, 22-25
      creating at runtime using reflection, 456
      default values for, 68
      suffixes of numbers indicating, 24

U[ Top ]
uint type, 22, 23
uint16 type, 22
uint32 type, 22
uint64 type, 23
ulong type, 23
UML (Unified Modeling Language), 98
unconditional branching statements, 34
      (see also jump statements)
#undef directive, 60
UnderlyingObject property, XPathNavigator, 327
Unified Modeling Language (UML), 98
unmanaged code, invoking from C#, 551-554
unmanaged resources, cleaning up, 112
unsafe keyword, 554, 556, 567
unsubscribe operator (-=), 266
unwinding the stack, 241, 245
user-defined types, 21
ushort type, 22, 23
using directive, 13
using keyword, 567
using statement, 80

V[ Top ]
validation controls, 401
value keyword, 93
value types, 129
Values property, Dictionary, 211
variables, 25-26
      assigning values to, 25, 27, 49
      declaring, 25
      implicitly types local variables, 291
      initializing, 25, 27
      naming conventions for, 14
      on the stack, 23
      (see also member variables)
verbatim string literals, 215
versioning, 106
ViewState property, web control, 384
virtual keyword, 101, 567
      (see also overriding methods)
Visual Basic 6
      ADO compared to ADO.NET, 369
      array size, differences in, 158
      controls, differences in, 425
      loop variable differences, 46
      switch statement eqivalents in, 40
      variables in try blocks, restrictions on, 252
Visual Studio
      compiling programs, 17
      creating projects, 15
      debugger (see debugger, Visual Studio)
      importing ActiveX controls using, 547
      LINQ to SQL designer, 344-348
      namespaces included by default, 13, 16
      version used for this book, x
      web-based applications created using, 382, 385

W[ Top ]
web controls (see ASP controls)
Web Forms, 381-383
      code separation used by, 382
      code-behind pages for, 381, 386-388
      controls for (see server-side controls)
      creating, 385-391
      event handlers for, 383
      events in, 383, 399-403
      life cycle of, 384
web site resources
      Adventure Works LT sample database, 338
      author, xi, xv
      code style guidelines by Microsoft, 14
      for this book, xvi
      Griffiths, Ian, blog for, 301
      Hungarian notation, 32
      Northwind database, 369
      port numbers, 512
      Project Gutenberg, 557
      security, 398
      Silverlight, 6
      source code for examples, xi
      support, xv
      XPath, 320
      XPath functions, 322
web streams, 527-529
web-based applications
      advantages of, 381
      state of, 384
      Visual Studio used for, 382
      (see also ASP.NET; Web Forms)
WebRequest object, 527
WebResponse object, 527
where clause of query, 282
Where() method, LINQ, 293
while keyword, 568
while loop, 43
whitespace, 33, 47
Wiltamuth, Scott (C# creator), 4
Windows Forms applications
      controls
            button, 432-437
            creating, 421
            populating, 424-428
            TreeView, 424-432
      creating, 420-421
      event handlers for, 423, 429-437
Windows Presentation Foundation (see WPF)
Windows Vista
      protected files, accessing, 492, 496
      version used for this book, x
WPF (Windows Presentation Foundation), 100, 404
      animation, 409-412
      books about, 405
      creating applications, 405-408
      data for application, 412-414
      event handling in, 418
      grids, 406-408
      stack panels, 406-408, 414
      styles, 409-412
      Windows version required for, x
      XAML in, 404, 414, 415-418
Write() method, Console, 46
WriteLine() method
      Console, 11, 26, 506
      StreamWriter, 504, 506

X[ Top ]
XAML (eXtensible Application Markup Language), 6, 404, 414, 415-418
XAttribute class, 363
XDocument class, 363
XElement class, 363
XHTML, 304
Xie, Donald (author), x
XML (eXtensible Markup Language), 302, 304
      creating documents, 304-311
      elements in, 303
      LINQ output to, 363-367
      tags in, 303
      versions of, 302
XML editor, 309
XML serialization, 329-331
      customizing using attributes, 331-333
      deserialization, 331
      runtime customization of, 333-336
XmlAttribute object, 309
XmlAttributeAttribute object, 333, 335
XmlAttributeOverrides class, 335
XML-based documentation, comments for, 11
XmlNode class, 318
XmlSerializer object, 330
XPath, 311-317
      functions for, 321
      search conditions (predicates) for, 318, 320-321
      searching for a node, 318-319
      searching using axes, 319
      searching using XPathNavigator, 322-328
      web site about, 320, 322
XPathExpression object, 328
XPathNavigator class, 322, 326
XPathNodeIterator object, 327





Return to Programming C# 3.0