HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
The fastest way for Java developers to pick up C# and .Net - by leveraging on what they already know in Java to learn the new language.
Intermediate.
Audience:
All intermediate Java developers.
Technology:
C# is a new programming language which is promoted by Microsoft as the successor to C++. C# together with Visual Basic .NET are the two most popular programming languages .NET developers use to write applications targeted at the .NET platform.
Author Biography:
Mok Heng Ngee is an experienced software developer and architect who has been involved in numerous large-scale software enterprise projects based on the Java 2 Platform, Enterprise Edition (J2EE). Mok has writes for Computer Times and has been invited to speak at the official launch of Visual Studio .NET in Singapore. He has been accorded MVP (Most Valuable Professional) status by Microsoft Asia.
About the author xiii
Preface xv
Introduction xvii
Acknowledgments xxi
Part 1 Introducing .NET and C# 1
1 Introducing .NET 3
1.1 Evolution: from COM to .NET 3
1.2 What exactly is .NET? 5
1.3 Multiple .NET programming languages and VS .NET 6
1.4 Intermediate language 8
1.5 The .NET common language runtime 9
1.6 Competing in parallel with Java technologies 12
1.7 Common language infrastructure 14
1.8 Other .NET-related technologies 19
1.9 Unsafe codes and real time programs 22
1.10 Porting .NET to other operating systems 23
2 Introducing C# 25
2.1 Potent combo of Java and C!! 26
3 JUMP to .NET and J# 30
3.1 Java Language Conversion Assistant 30
3.2 The J# language 30
4 Hello C#! 34
4.1 How to compile and run the code examples in this book 34
4.2 Some .NET specifics 36
4.3 Disassembling an assembly file 36
Part 2 Classes, methods, and other OO stuff 39
5 Getting started 41
5.1 Basic class structure 41
5.2 Basic console I_O 45
5.3 C# namespaces (Java packages) 50
Contents
6 Class issues 56
6.1 Class modifiers 56
6.2 Class members 56
6.3 Creating an object with the new operator 60
6.4 Looking at System.Object 61
6.5 Class inheritance 63
6.6 Implementing interfaces 65
6.7 Sealed classes (Java final classes) 73
6.8 Abstract classes 73
6.9 Nested classes (Java inner classes) 74
7 Method issues 78
7.1 Method modifiers 78
7.2 Method basics 79
7.3 Instance constructors 84
7.4 Static constructors (Java static initializers) 85
7.5 Destructors 87
7.6 Constructor initializers and constructor chaining 88
7.7 Method overloading 91
7.8 Passing variable numbers of parameters into C# methods 91
7.9 Abstract methods 94
7.10 Method overriding using the virtual and override modifiers 96
7.11 Method hiding with the new keyword 101
7.12 Static methods 105
7.13 Sealed methods (Java final methods) 107
8 Miscellaneous issues 109
8.1 Access modifiers 109
8.2 Static members 114
8.3 C# constants and read-only fields (Java final variables) 116
8.4 Volatile fields 119
Part 3 Types, operators, and flow control 123
9 C# types 125
9.1 Pointer types 126
9.2 Reference types 126
9.3 Value types 129
9.4 Unsigned types in C# 132
9.5 The decimal type 133
9.6 The char type 133
9.7 The string type and string literals 134
9.8 All types are objects 136
9.9 Casting for reference types 139
9.10 Casting for value types 140
9.11 Common typing with other .NET languages 142
10 C# operators 144
10.1 Operators and their precedence in C# 144
10.2 Operator overloading 149
10.3 typeof operator 150
10.4 checked and unchecked operators and statements 153
10.5 The # # operator 159
10.6 The is operator (Java's instanceof operator) 162
10.7 The as operator 164
11 Iteration and flow control 167
11.1 Looping with the while, do, for, continue and break keywords 167
11.2 Conditional statements using the if and else keywords 170
11.3 Looping with the foreach keyword 171
11.4 Conditional statements with the switch and case keywords 173
11.5 Flow control with the break and continue keywords 174
11.6 Flow control with the goto keyword 175
Part 4 Core topics 181
12 Arrays 183
12.1 One-dimensional arrays 184
12.2 Multi-dimensional arrays: rectangular arrays 185
12.3 Multi-dimensional arrays: jagged arrays 187
12.4 Mixing jagged and rectangular arrays 189
12.5 Using the System.Array class 190
13 Exception handling 193
13.1 Exception examples 193
13.2 C# exception hierarchy 204
13.3 Examining System.Exception 206
13.4 Inner exceptions 208
13.5 Catching generic exceptions 210
14 C# delegates 212
14.1 What are delegates? 212
14.2 A first delegate example 215
14.3 Combining delegates 216
14.4 Removing delegates 219
14.5 Exception throwing in delegates 221
14.6 Passing method parameter