TY - BOOK AU - Balagurusamy, TI - Programming in C ++: a primer SN - 97800707025073 (pb) U1 - 005.114 PY - 2010/// CY - New Delhi PB - Mc Graw Hill KW - Computer Programming N1 - includes index; 1. Introducing C# 1.1 What is C#? 1 1.2 WhyC#? 1 1.3 Evolution of C# 3 1.4 Characteristics of C# 4 1.5 Applications of C# 5 1.6 How does C# Differ from €++ ? 6 1.7 How does C# Differ from Java ? 7 Ca^e Study 8 Review Questions 9 2. Understanding .NET: The C# Environment 2.1 The .Net Strategy 11 2.2 The Origins of .NET Technology 12 2.3 The .NET Framework 13 2.4 The Common Language Runtime 13 2.5 Framework Base Classes 15 2.6 User and Program Interfaces 15 2.7 Visual Studio .NET 15 2.8 .NET Languages 15 2.9 Benefits of the .NET Approach 16 2.10 C# and the .NET 16 Case Study 17 Review Questions 17 3. Overview of C# 3.1 Introduction 18 3.2 A Simple C# Program 18 3.3 Namespaces 20 3.4 Adding Comments 21 3.5 Main Returning a Value 22 3.6 Using Aliases for Namespace Classes 22 3.7 Passing String Objects to WriteLine Method 23 3.8 Command Line Arguments 23 3.9 Main with a Class 25 3.10 Providing Interactive Input 26 3.11 Using Mathematical Functions 2 7 3.12 Multiple Main Methods 28 3.13 Compile Time Errors 28 3.14 Program Structure 29 3.15 Program Coding Style 30 Case Study 30 Common Programming Errors 31 Review Questions 32 Debugging Exercises 32 Programming Exercises, 33 Literals, Variables and Data Types 4.1 Introduction 34 4.2 Literals 36 4.3 Variables 39 4.4 Data Types 39 4.5 Value Types 40 4.6 Reference Types 43 A.l Declaration of Variables 43 4.8 Initialization of Variables 44 4.9 Default Values 44 4.10 Constant Variables 45 4.11 Scope of Variables 46 4.12 Boxing and Unboxing 48 Case Study 49 Common Programming Errors 50 Review Questions 51 Debugging Exercises 52 Programming Exercises 53 Operators and Expressions 5.1 Introduction 55 5.2 Arithmetic Operators 55 5.3 Relational Operators 57 5.4 Logical Operators 58 5.5 Assigmnent Operators 59 5.6 Increment and Decrement Operators 59 5.7 Conditional Operator 60 5.8 Bitwise Operators 61 5.9 Special Operators 62 5.10 Arithmetic Expressions 62 5.11 Evaluation of Expressions 63 5.12 Precedence of Arithmetic Operators 64 5.13 Type Conversions 65 5.14 Operator Precedence and Associativity 69 5.15 Mathematical Functions 72 Case Study 73 Common Programming Errors 75 Review Questions 75 Debugging Exercises 77 Programming Exercises 77 6. Decision Making and Branching 6.1 Introduction 80 6.2 Decision Making with if Statement 80 6.3 Simple if Statement 81 6.4 The if... else Statement 82 6.5 Nesting of if... else Statements 86 6.6 The else if Ladder 88 6.7 The Switch Statement 90 6.8 The ? : Operator 95 Case Study 96 Common Programming Errors 97 Review Questions 98 Debugging Exercises 99 Programming Exercises 100 7. Decision Making and Looping 7.1 Introduction 102 7.2 The while Statement 103 7.3 The do Statement 104 1A The for Statement 108 7.5 The foreach Statement 113 7.6 Jiunps in Loops 114 Case Study 118 Common Programming Errors 120 Review Questions 120 Debugging Exercises 123 Programming Exercises 124 8. Methods in C# 8.1 Introduction 125 8.2 Declaring Methods 125 8.3 The Main Method 126 8.4 Invoking Methods 127 8.5 Nesting of Methods 128 8.6 Method Parameters 129 8.7 Pass by Value 129 | 8.8 Pass by Reference 130 i 8.9 The Output Parameters 131 8.10 Variable Argument Lists 132 8.11 Methods Overloading 135 Case Study 137 Common Programming Errors 140 . Review Questions 141 Debugging Exercises 142 Programming Exercises 143 Handling Arrays 9.1 Introduction 145 9.2 One-Dimensional Arrays 145 9.3 Creating an Array 146 9.4 Two-Dimensional Arrays 150 9.5 Variable-Size Arrays 152 9.6 The System.Array Class 153 9.7 ArrayList Class 154 Case Study 160 Common Programming Errors 163 Review Questions 163 Debugging Exercises 164 Programming Exercises 165 10. Manipulating Strings 10.1 Introduction 168 10.2 Creating Strings 168 10.3 String Methods 170 10.4 Inserting Strings 171 10.5 Comparing Strings 173 10.6 Finding Substrings 174 10.7 Mutable Strings 174 10.8 Arrays of Strings 177 10.9 Regular Expressions 179 Case Study 182 Common Programming Errors 184 Review Questions 185 Debugging Exercises 186 Programming Exercises 188 11. Structures and Enumerations 11.1 Introduction 7 90 11.2 Structures 190 11.3 Structs with Methods 192 11.4 Nested Structs 194 11.5 Differences between Classes and Structs 197 11.6 Enumerations 198 11.7 Enumerator Initialization 201 11.8 Enumerator Base Types 202 11.9 Enumerator Type Conversion 203 Case Study 204 Common Programming Errors 206 Review Questions 206 Debugging Exercises 208 Programming Exercises 210 12. Classes and Objects 12.1 Introduction 212 12.2 Basic Principles of OOP 212 12.3 Defining a Class 213 12.4 Adding Variables 213 12.5 Adding Methods 214 12.6 Member Access Modifiers 216 12.7 Creating Objects 217 12.8 Accessing Class Members 218 12.9 Constructors 219 12.10 Overloaded Constructors 221 12.11 Static Members 222 12.12 Static Constructors 223 12.13 Private Constructors 223 ,12.14 Copy Constructors 223 12.15 Destructors 224 12.16 Member Initialization 224 12.17 The this Reference 225 12.18 Nesting of Classes 225 12.19 Constant Members 227 12.20 Read-only Members 227 12.21 Properties 228 12.22 Indexers 230 Case Study 233 Common Programming Errors 235 Review Questions 236 Debugging Exercises 240 Programming Exercises 242 13. Inheritance and Polymorphism 13.1 Introduction 244 13.2 Classical Inheritance 244 13.3 Containment Inheritance 245 13.4 Defining a Subclass 245 13.5 Visibility Control 247 13.6 Defining Subclass Constructors 250 13.7 Multilevel Inheritance 252 13.8 Hierarchical Inheritance 256 13.9 Overriding Methods 256 13.10 Hiding Methods 257 13.11 Abstract Classes 259 13.12 Abstract Methods 259 13.13 Sealed Classes: Preventing Inheritance 260 13.14 Sealed Methods 260 13.15 Polymorphism 261 Case Study 266 Common Programming Errors 268 Review Questions 268 Debugging Exercises 271 Programming Exercises 272 14. Interface: Multiple Inheritance 14.1 Introduction 275 14.2 Defining an Interface 275 14.3 Extending an Interface 276 14.4 Implementing Interfaces 277 14.5 Interfaces and Inheritance 280 14.6 Explicit Interface Implementation 281 14.7 Abstract Class and Interfaces 284 Case Study 287 Common Programming Errors 289 Review Questions 289 Debugging Exercises 291 15. Operator Overloading 15.1 Introduction 295 15.2 Overloadable Operators 295 15.3 Need for Operator Overloading 296 15.4 Defining Operator Overloading 296 15.5 Overloading Unary Operators 297 15.6 Overloading Binary Operators 298 15.7 Overloading Comparison Operators 300 Case Study 307 Common Programming Errors 309 Review Questions 309 Debugging Exercises 310 Programming Exercises 314 16. Delegates and Events 16.1 Introduction 315 16.2 Delegates 315 16.3 Delegate Declaration 316 16.4 Delegate Methods 316 16.5 Delegate Instantiation 317 16.6 Delegate Invocation 319 16.7 Using Delegates 319 16.8 Multicast Delegates 320 16.9 Events 322 Case Study 329 Review Questions 331 Debugging Exercises 333 17. Managing Console I/O Operations 17.1 Introduction 336 17.2 The Console Class 336 17.3 Console Input 336 17.4 Console Output 337 17.5 Formatted Output 339 17.6 Numeric Formatting 340 ll.l Standard Numeric Format 340 17.8 Custom Numeric Format 342 Case Study 345 Review Questions 348 Debugging Exercises 348 Programming Exercises 350 18. Managing Errors and Exceptions 18.1 Introduction 352 18.2 What is Debugging? 352 18.3 Types of Errors 352 18.4 Exceptions 354 18.5 Syntax ofException Handling Code 355 18.6 Multiple Catch Statements 357 18.7 The Exception Hierarchy 358 18.8 General Catch Handler 359 18.9 Using Finally Statement 360 18.10 Nested Try Blocks 361 18.11 Throwing Our Own Exceptions 363 18.12 Checked and Unchecked Operators 368 18.13 Using Exceptions for Debugging 368 Case Study 368 Common Programming Errors 371 Review Questions 372 Debugging Exercises 3 73 Programming Exercises 376 19. Multithreading in C# 19.1 Introduction 377 19.2 Understanding the System.Threading Namespace 377 19.3 Creating and Starting a Thread 380 19.4 Scheduling a Thread 382 19.5 Synchronising Threads 384 19.6 Thread Pooling 386 Case Study 388 Common Programming Errors 390 Review Questions 390 Programming Exercises 390 20. WindowForms and Web-based Application Development on .NET 20.1 Introduction 392 20.2 Creating WindowForms 392 20.3 Customizing a Form 394 20.4 Understanding Microsoft Visual Studio 2005 398 20.5 Creating and Running a SampleWinApp Windows Application 402 20.6 Overview of Design Patterns 407 20.7 Creating and Running a SampleWinApp2 Windows Application 408 20.8 Web-based Application on .NET 418 Case Study 433 Common Programming Errors 43 7 Review Questions 437 Programming Exercises 438 ER -