Documente Academic
Documente Profesional
Documente Cultură
O'REILLY®
Beijing • Cambridge • Farnham • Köln • Sebastopol • Taipei • Tokyo
Table of Contents
Preface xv
3. C# Language Fundamentals 46
Statements 46
Types 47
Numeric Types 48
Nonnumeric Types: char and bool 49
Types and Compiler Errors 50
WriteLine() and Output 51
Variables and Assignment 52
Definite Assignment 54
Implicitly Typed Variables 55
Casting 56
Constants 58
Literal Constants 58
Symbolic Constants 58
Enumerations 60
S trings 63
Whitespace 63
Summary 64
Test Your Knowledge: Quiz 65
Test Your Knowledge: Exercises 66
vi I Table of Contents
4. Operators 68
Expressions 68
The Assignment Operator (=) 69
Mathematical Operators 69
Simple Arithmetic Operators (+, *, /) 70
The Modulus Operator (%) 71
Increment and Decrement Operators 72
The Calculate and Reassign Operators 72
Increment or Decrement by 1 73
The Prefix and Postfix Operators 73
Relational Operators 75
Logical Operators and Conditionals 77
The Conditional Operator 78
Operator Precedence 79
Summary 81
Test Your Knowledge: Quiz 82
Test Your Knowledge: Exercises 83
5. Branching 85
Unconditional Branching Statements 86
Conditional Branching Statements 88
if Statements 88
Single-Statement if Blocks 90
Short-Circuit Evaluation 92
if else Statements 94
Nested if Statements 95
switch Statements 98
Fall-Through and Jump-to Cases 101
Switch an string Statements 102
ReadLine( ) and Input 103
Iteration (Looping) Statements 104
Creating Loops with goto 105
The while Loop 106
The do ...while Loop 108
The for Loop 109
Summary 118
Test Your Knowledge: Quiz 119
Test Your Knowledge: Exercises 120
Takle nf Cnntentgvii
6. Object-Oriented Programming 121
Creating Models 123
Classes and Objects 123
Defining a Class 124
Class Relationships 125
The Three Pillars of Object-Oriented Programming 126
Encapsulation 126
Specialization 127
Polymorphism 128
Object-Oriented Analysis and Design 129
Summary 130
Test Your Knowledge: Quiz 131
Test Your Knowledge: Exercises 131
Table of Contents 1 ix
Summary 216
Test Your Knowledge: Quiz 217
Test Your Knowledge: Exercises 218
x Table of Contents
Casting to an Interface 270
The is and as Operators 270
Extending Interfaces 276
Combining Interfaces 279
Overriding Interface Methods 280
Explicit Interface Implementation 285
Summary 288
Test Your Knowledge: Quiz 290
Test Your Knowledge: Exercises 290
Table of Contents 1 xi
Testing for Equality 339
Other Useful String Methods 341
Finding Substrings 344
Splitting Strings 346
The StringBuilder Class 348
Regular Expressions 350
The Regex Class 351
Summary 353
Test Your Knowledge: Quiz 354
Test Your Knowledge: Exercises 355
Index 649