CONTENTS

Foreword xi

Preface xiii

C# - where from and where to xiii
Outline of the book xiv
Our approach xv
The Views system xvi
Acknowledgements xvii

List of figures xviii

Chapter 1: Introduction 1

1.1 Preamble 1
1.2 The role of programming languages 2
1.3 About compilation 7
1.4 Interactive development environments 12
1.5 Getting started with C# 14
Concepts in Chapter 1 18
Quiz 18
Exercises 19

Chapter 2: Using objects 20

2.1 Introduction to objects 20
2.2 Members of objects 26
2.3 The structure of a program 32
2.4 Strings, output and formatting 40
2.5 Variables, assignments and input 42
2.6 Understanding C#'s APIs 51
Concepts in Chatper 2 56
Quiz 57
Exercises 58

Chapter 3: Inside objects 61

3.1 The structure of a type 61
3.2 Fields and properties 65
3.3 Numeric types 71
3.4 Expressions 74
3.5 Simple loops 82
3.6 Output formatting 89
3.7 Methods and parameters 93
3.8 Case study 1 - Phone bill comparison 99
Concepts in Chapter 3 105
Quiz 106
Exercises 108

Chapter 4: Control and arrays 110

4.1 Boolean expressions 111
4.2 Selection statements 114
4.3 Repetition statements 116
4.4 Simple arrays 126
4.5 String and characters 133
4.6 Additional selection statements 143
4.7 Case study 2 - The Rock-Paper-Scissors game 149
Concepts in Chapter 4 153
Quiz 154
Exercises 158

Chapter 5: Graphical user interfaces with Views 161

5.1 Graphical user interfaces 162
5.2 Elements of a GUI 163
5.3 Introduction to Views 168
5.4 Views layout 177
5.5 Views controls 180
5.6 Views methods 187
5.7 Advanced uses of Views 192
5.8 Case study 3 - The supermarket till 198
Concepts in Chapter 5 204
Quiz 204
Problems 206

Chapter 6: Exception and debugging 208

6.1 Errors 208
6.2 Exception Handling 211
6.3 Debugging 214
6.4 Using a debugger program 224
Concepts in Chapter 6 230
Quiz 231

Chapter 7: Files and streams 235

7.1 Files and streams 233
7.2 Streams for output 235
7.3 Streams for input 237
7.4 File processing as a design pattern 241
7.5 Files in vewis 245
Concepts in Chapter 7 256
Quiz 256
Exercises 258

Chapter 8: Collections 261

8.1 More about classes 261
8.2 Collections 271
8.3 Arrays as collections 275
8.4 Sorted listed 286
8.5 Case study 4 - Training schedules 296
Concepts in Chapter 8 303
Quiz 304
Exercises 306

Chapter 9: Polymorphism and inheritance 309

9.1 Objects in a changing world 309
9.2 Interfaces for polymorphism 312
9.3 Extensibility with inheritance 327
9.4 Case study 5 - Enhancing the starlords 333
9.5 Serialization 341
Concepts in Chapter 9 343
Quiz 344
Exercises 347

Chapter 10: Graphics and networking 348

10.1 Graphics interfaces 348
10.2 Simple graphics features 349
10.3 Images 355
10.4 Animation with threads 358
10.5 Networking 372
10.6 Case study 6 - An ATM client server system 375
Concpets in Chapter 10 381
Quiz 382
Exercises 383

Appendix A: List of Forms 385

Appendix B: Keywords and operators 387

B.1 Keywords 387
B.2 Operators and punctuators 389

Appendix C: Formatters 390

C.1 Format specification 390
C.2 Number format specifiers 391
C.3 Customizing number formatters 392
C.4 DateTime formatters 393

Appendix D: Formatters 395

D.1 Inputting Unicode characters 395
D.2 Selected characters 396

Appendix E: Useful namespaces 398

E.1 The .NET framework class library 398
E.2 Usage of the namespaces 406

Appendix F: The Views.Form class 408

F.1 Creating Forms with Views 408
F.2 Syntax of specification for Views.Form 409
F.3 Grouping tags 411
F.4 Control tags 412
F.5 Attribute values 415
F.6 Views.Form methods 417
F.7 Recommended coding style 419
F.8 Use of the indexer operation 420

Appendix G: Debugging with Windows 421

G.1 Introduction 421
G.2 The cordbg debugger 422
G.3 The Just-In-Time debugger 428
G.4 The Visual Studio debugger 429