Suchen und Finden
Contents at a Glance
5
Contents
7
About the Author
23
About the Technical Reviewer
24
Acknowledgments
25
Introduction
26
C# and the .NET Framework
27
Before . NET
28
Enter Microsoft . NET
28
Compiling to the Common Intermediate Language ( CIL)
33
Compiling to Native Code and Execution
34
The Common Language Runtime ( CLR)
36
The Common Language Infrastructure ( CLI)
37
Review of the Acronyms
39
Overview of C# Programming
40
A Simple C# Program
41
More About SimpleProgram
42
Identifiers and Keywords
43
Naming Conventions
44
Keywords
45
Main: The Starting Point of a Program
46
Whitespace
46
Statements
47
Simple Statements
47
Blocks
47
Text Output from a Program
49
Write
49
WriteLine
50
The Format String
51
Multiple Markers and Values
52
Comments: Annotating the Code
53
More About Comments
54
Documentation Comments
54
Summary of Comment Types
55
Types, Storage, and Variables
56
A C# Program Is a Set of Type Declarations
57
A Type Is a Template
58
Instantiating a Type
58
Data Members and Function Members
59
Predefined Types
60
User- Defined Types
62
The Stack and the Heap
63
Value Types and Reference Types
65
Variables
67
Classes: The Basics
70
Overview of Classes
71
Programs and Classes: A Quick Example
72
Declaring a Class
73
Class Members
74
Creating Variables and Instances of a Class
77
Allocating Memory for the Data
78
Instance Members
80
Access Modifiers
81
Accessing Members from Inside the Class
84
Accessing Members from Outside the Class
85
Putting It All Together
87
Methods
89
The Structure of a Method
90
Local Variables
92
Local Constants
95
Method Invocations
97
Return Values
98
Parameters
102
Value Parameters
105
Reference Parameters
108
Output Parameters
111
Parameter Arrays
114
Summary of Parameter Types
118
Stack Frames
119
Recursion
121
Method Overloading
123
More About Classes
124
Class Members
125
Instance Class Members
127
Static Fields
128
Accessing Static Members from Outside the Class
129
Static Function Members
131
Other Static Class Member Types
132
Member Constants
133
Properties
136
Instance Constructors
149
Static Constructors
152
Object Initializers
154
Destructors
156
Comparing Constructors and Destructors
160
The readonly Modifier
161
The this Keyword
163
Indexers
164
Access Modifiers on Accessors
173
Partial Classes and Partial Types
174
Classes and Inheritance
178
Class Inheritance
179
Accessing the Inherited Members
180
Hiding Members of a Base Class
182
Base Access
184
Using References to a Base Class
185
Constructor Execution
192
Inheritance Between Assemblies
197
Member Access Modifiers
199
Abstract Members
205
Abstract Classes
206
Sealed Classes
208
Static Classes
209
Extension Methods
210
External Methods
214
Expressions and Operators
216
Expressions
217
Literals
218
Integer Literals
219
Character Literals
221
String Literals
222
Order of Evaluation
224
Simple Arithmetic Operators
226
The Remainder Operator
227
Relational and Equality Comparison Operators
228
Increment and Decrement Operators
230
Conditional Logical Operators
232
Logical Operators
234
Shift Operators
236
Assignment Operators
238
The Conditional Operator
240
Unary Arithmetic Operators
242
User- Defined Type Conversions
243
Operator Overloading
246
The typeof Operator
249
Statements
252
What Are Statements?
253
Expression Statements
254
Flow- of- Control Statements
255
The if Statement
256
The if . . . else Statement
257
The switch Statement
258
The while Loop
263
The do Loop
264
The for Loop
266
Jump Statements
270
The break Statement
270
The continue Statement
271
Labeled Statements
272
The goto Statement
274
The using Statement
275
Other Statements
280
Namespaces and Assemblies
281
Referencing Other Assemblies
282
Namespaces
287
The using Directives
293
The Structure of an Assembly
295
The Identity of an Assembly
297
Strongly Named Assemblies
299
Private Deployment of an Assembly
301
Shared Assemblies and the GAC
302
Configuration Files
304
Delayed Signing
305
Exceptions
307
What Are Exceptions?
308
The try Statement
309
The Exception Classes
311
The catch Clause
312
Examples Using Specific catch Clauses
313
The catch Clauses Section
314
The finally Block
315
Finding a Handler for an Exception
316
Searching Further
317
Throwing Exceptions
321
Throwing Without an Exception Object
322
Structs
324
What Are Structs?
325
Structs Are Value Types
326
Assigning to a Struct
327
Constructors and Destructors
328
Field Initializers Are Not Allowed
331
Structs Are Sealed
331
Boxing and Unboxing
331
Structs As Return Values and Parameters
332
Additional Information About Structs
332
Enumerations
333
Enumerations
334
Bit Flags
338
More About Enums
344
Arrays
346
Arrays
347
Types of Arrays
348
An Array As an Object
349
One- Dimensional and Rectangular Arrays
350
Instantiating a One- Dimensional or Rectangular Array
351
Accessing Array Elements
352
Initializing an Array
353
Jagged Arrays
358
Comparing Rectangular and Jagged Arrays
362
The foreach Statement
363
Array Covariance
368
Useful Inherited Array Members
369
Comparing Array Types
373
Delegates
374
What Is a Delegate?
375
Declaring the Delegate Type
376
Creating the Delegate Object
377
Assigning Delegates
379
Combining Delegates
380
Adding Methods to Delegates
381
Removing Methods from a Delegate
382
Invoking a Delegate
383
Delegate Example
383
Invoking Delegates with Return Values
385
Invoking Delegates with Reference Parameters
387
Anonymous Methods
389
Lambda Expressions
394
Events
397
Events Are Like Delegates
398
Overview of Source Code Components
400
Declaring an Event
401
Raising an Event
403
Subscribing to an Event
404
Standard Event Usage
407
The MyTimerClass Code
412
Event Accessors
414
Interfaces
415
What Is an Interface?
416
Declaring an Interface
420
Implementing an Interface
422
An Interface Is a Reference Type
424
Using the as Operator with Interfaces
426
Implementing Multiple Interfaces
427
Implementing Interfaces with Duplicate Members
428
References to Multiple Interfaces
430
An Inherited Member As an Implementation
432
Explicit Interface Member Implementations
433
Interfaces Can Inherit Interfaces
437
Conversions
440
What Are Conversions?
441
Implicit Conversions
442
Explicit Conversions and Casting
443
Types of Conversions
445
Numeric Conversions
445
Reference Conversions
453
Boxing Conversions
459
Unboxing Conversions
461
User- Defined Conversions
463
The is Operator
468
The as Operator
469
Generics
470
What Are Generics?
471
Generics in C#
473
Generic Classes
475
Declaring a Generic Class
476
Creating a Constructed Type
477
Creating Variables and Instances
478
Constraints on Type Parameters
483
Generic Structs
486
Generic Interfaces
487
Generic Delegates
490
Generic Methods
493
Extension Methods with Generic Classes
498
Enumerators and Iterators
500
Enumerators and Enumerable Types
501
Using the IEnumerator Interface
503
The IEnumerable Interface
508
The Non- Interface Enumerator
511
The Generic Enumeration Interfaces
513
The IEnumerator< T> Interface
514
The IEnumerable< T> Interface
517
Iterators
519
Common Iterator Patterns
524
Producing Enumerables and Enumerators
525
Producing Multiple Enumerables
526
Producing Multiple Enumerators
528
Behind the Scenes with Iterators
530
Introduction to LINQ
531
What Is LINQ?
532
LINQ Providers
533
Query Syntax and Method Syntax
536
Query Variables
538
The Structure of Query Expressions
540
The Standard Query Operators
558
LINQ to XML
569
Introduction to Asynchronous Programming
589
Processes, Threads, and Asynchronous Programming
590
Asynchronous Programming Patterns
593
BeginInvoke and EndInvoke
594
Timers
605
Preprocessor Directives
608
What Are Preprocessor Directives?
609
General Rules
609
The # define and # undef Directives
611
Conditional Compilation
612
The Conditional Compilation Constructs
613
Diagnostic Directives
616
Line Number Directives
617
Region Directives
618
The # pragma warning Directive
619
Reflection and Attributes
620
Metadata and Reflection
621
The Type Class
621
Getting a Type Object
623
What Is an Attribute?
626
Applying an Attribute
627
Predefined, Reserved Attributes
628
More About Applying Attributes
632
Custom Attributes
635
Accessing an Attribute
643
Other Topics
645
Overview
646
Strings
646
Parsing Strings to Data Values
653
Nullable Types
654
Method Main
661
Documentation Comments
663
Nested Types
666
Index
671
Alle Preise verstehen sich inklusive der gesetzlichen MwSt.