Learning C# 3.0

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

If you're new to C#, this popular book is the ideal way to get started. Completely revised for the latest version of the language, Learning C# 3.0 starts with the fundamentals and takes you through intermediate and advanced C# features -- including generics, interfaces, delegates, lambda expressions, and LINQ. You'll also learn how to build Windows applications and handle data with C#. No previous programming experience is required -- in fact, if you've never written a line of code in your life, bestselling authors Jesse Liberty and Brian MacDonald will show you how it's done. Each chapter offers a self-contained lesson to help you master key concepts, with plenty of annotated examples, illustrations, and a concise summary. With this book, you will: Learn how to program as you learn C# Grasp the principles of object-oriented programming through C# Discover how to use the latest features in C# 3.0 and the .NET 3.5 Framework--including LINQ and the Windows Presentation Foundation (WPF) Create Windows applications and data-driven applications You'll also find a unique Test Your Knowledge section in each chapter, with practical exercises and review quizzes, so you can practice new skills and test your understanding. If you're ready to dive into C# and .NET programming, this book is a great way to quickly get up to speed.

Author(s): Jesse Liberty, Brian MacDonald
Edition: 3rd
Publisher: O'Reilly Media
Year: 2008

Language: English
Pages: 694

Table of Contents......Page 7
Preface......Page 17
Who This Book Is For......Page 18
How This Book Is Organized......Page 19
Support: A Note from Jesse Liberty......Page 22
We’d Like to Hear from You......Page 23
Brian MacDonald......Page 24
C# and .NET Programming......Page 27
Installing C# Express......Page 28
C# 3.0 and .NET 3.5......Page 29
The .NET Framework......Page 30
The C# Language......Page 31
Your First Program: Hello World......Page 32
The Compiler......Page 36
Examining Your First Program......Page 37
The Integrated Development Environment......Page 42
Summary......Page 43
Test Your Knowledge: Quiz......Page 44
Test Your Knowledge: Exercise......Page 45
Visual Studio 2008 and C# Express 2008......Page 46
Projects and Solutions......Page 48
Project Types......Page 50
Templates......Page 51
Inside the Integrated Development Environment......Page 52
Building and Running Applications......Page 54
The File Menu......Page 55
Find and Replace......Page 56
Insert File As Text......Page 58
Incremental search......Page 59
Outlining......Page 60
IntelliSense......Page 61
The View Menu......Page 62
Output......Page 63
Properties......Page 64
Other Windows......Page 66
The Data Menu......Page 67
Code Snippets Manager......Page 68
The Window Menu......Page 69
Summary......Page 70
Test Your Knowledge: Exercises......Page 71
Statements......Page 72
Types......Page 73
Numeric Types......Page 74
Nonnumeric Types: char and bool......Page 75
Types and Compiler Errors......Page 76
WriteLine() and Output......Page 77
Variables and Assignment......Page 78
Definite Assignment......Page 80
Implicitly Typed Variables......Page 81
Casting......Page 82
Symbolic Constants......Page 84
Enumerations......Page 86
Whitespace......Page 89
Summary......Page 90
Test Your Knowledge: Quiz......Page 91
Test Your Knowledge: Exercises......Page 92
Expressions......Page 94
Mathematical Operators......Page 95
Simple Arithmetic Operators (+, –, *, /)......Page 96
The Modulus Operator (%)......Page 97
The Calculate and Reassign Operators......Page 98
The Prefix and Postfix Operators......Page 99
Relational Operators......Page 101
Logical Operators and Conditionals......Page 103
The Conditional Operator......Page 104
Operator Precedence......Page 105
Summary......Page 107
Test Your Knowledge: Quiz......Page 108
Test Your Knowledge: Exercises......Page 109
Branching......Page 111
Unconditional Branching Statements......Page 112
if Statements......Page 114
Single-Statement if Blocks......Page 116
Short-Circuit Evaluation......Page 118
if...else Statements......Page 120
Nested if Statements......Page 121
switch Statements......Page 124
Fall-Through and Jump-to Cases......Page 127
Switch on string Statements......Page 128
ReadLine() and Input......Page 129
Iteration (Looping) Statements......Page 130
Creating Loops with goto......Page 131
The while Loop......Page 132
The do...while Loop......Page 134
The for Loop......Page 135
Controlling a for loop with the modulus operator......Page 136
Breaking out of a for loop......Page 137
The continue statement......Page 138
Optional for loop header elements......Page 140
Summary......Page 144
Test Your Knowledge: Quiz......Page 145
Test Your Knowledge: Exercises......Page 146
Object-Oriented Programming......Page 147
Classes and Objects......Page 149
Defining a Class......Page 150
Class Relationships......Page 151
Encapsulation......Page 152
Specialization......Page 153
Polymorphism......Page 154
Object-Oriented Analysis and Design......Page 155
Summary......Page 156
Test Your Knowledge: Exercises......Page 157
Classes and Objects......Page 159
Defining Classes......Page 160
Instantiating Objects......Page 161
Creating a Box Class......Page 163
Access Modifiers......Page 164
Method Arguments......Page 165
Return Types......Page 167
Constructors......Page 168
Initializers......Page 170
Anonymous Types......Page 172
The this Keyword......Page 173
Static and Instance Members......Page 174
Invoking Static Methods......Page 175
Using Static Fields......Page 177
Finalizing Objects......Page 180
Memory Allocation: The Stack Versus the Heap......Page 181
Summary......Page 187
Test Your Knowledge: Quiz......Page 188
Test Your Knowledge: Exercises......Page 189
Overloading Methods......Page 191
Encapsulating Data with Properties......Page 194
The get Accessor......Page 197
The set Accessor......Page 198
Returning Multiple Values......Page 199
Passing Value Types by Reference......Page 201
out Parameters and Definite Assignment......Page 203
Test Your Knowledge: Quiz......Page 204
Test Your Knowledge: Exercises......Page 205
Basic Debugging......Page 206
Setting a Breakpoint......Page 207
Setting Conditions and Hit Counts......Page 209
Examining Values: The Autos and Locals Windows......Page 210
Setting Your Watch......Page 214
The Call Stack......Page 215
Stopping Debugging......Page 216
Summary......Page 217
Test Your Knowledge: Quiz......Page 218
Test Your Knowledge: Exercises......Page 219
Using Arrays......Page 223
Declaring Arrays......Page 224
Accessing Array Elements......Page 225
Arrays and Loops......Page 226
The foreach Statement......Page 229
The params Keyword......Page 230
Multidimensional Arrays......Page 231
Rectangular Arrays......Page 232
Jagged Arrays......Page 236
Array Methods......Page 239
Sorting Arrays......Page 240
Summary......Page 242
Test Your Knowledge: Quiz......Page 243
Test Your Knowledge: Exercises......Page 244
Specialization and Generalization......Page 245
Implementing Inheritance......Page 248
Hiding the Base Class Method......Page 251
Controlling Access......Page 252
Creating Polymorphic Types......Page 253
Using Objects Polymorphically......Page 256
Versioning with new and override......Page 258
Abstract Classes......Page 260
The Root of All Classes: Object......Page 263
Summary......Page 266
Test Your Knowledge: Exercises......Page 267
Designing the Fraction Class......Page 269
Using the operator Keyword......Page 270
The Equals Operator......Page 274
Conversion Operators......Page 279
Summary......Page 283
Test Your Knowledge: Quiz......Page 284
Test Your Knowledge: Exercises......Page 285
What Interfaces Are......Page 286
Implementing an Interface......Page 288
Defining the Interface......Page 291
Implementing the Interface on the Client......Page 292
Implementing More Than One Interface......Page 293
The is and as Operators......Page 296
Extending Interfaces......Page 302
Combining Interfaces......Page 305
Overriding Interface Methods......Page 306
Explicit Interface Implementation......Page 311
Summary......Page 314
Test Your Knowledge: Exercises......Page 316
Generics......Page 318
Creating Indexers......Page 319
Indexing on Other Values......Page 324
Generic Collection Interfaces......Page 328
The IEnumerable Interface......Page 329
Generic Lists: List......Page 333
Sorting objects with the generic list......Page 336
Controlling sorting by implementing IComparer......Page 340
Generic Queues......Page 345
Generic Stacks......Page 348
Dictionaries......Page 351
Summary......Page 354
Test Your Knowledge: Quiz......Page 355
Test Your Knowledge: Exercises......Page 356
Strings......Page 357
Escape Characters......Page 358
The ToString() Method......Page 359
Comparing Strings......Page 360
Concatenating Strings......Page 362
Copying Strings......Page 363
Testing for Equality......Page 365
Other Useful String Methods......Page 367
Finding Substrings......Page 370
Splitting Strings......Page 372
The StringBuilder Class......Page 374
Regular Expressions......Page 376
The Regex Class......Page 377
Summary......Page 379
Test Your Knowledge: Quiz......Page 380
Test Your Knowledge: Exercises......Page 381
Throwing and Catching Exceptions......Page 383
Searching for an Exception Handler......Page 384
The throw Statement......Page 385
The try and catch Statements......Page 387
How the Call Stack Works......Page 390
Creating Dedicated catch Statements......Page 392
The finally Statement......Page 394
Exception Class Methods and Properties......Page 396
Custom Exceptions......Page 400
Summary......Page 403
Test Your Knowledge: Exercises......Page 404
Delegates and Events......Page 406
Delegates......Page 407
Events......Page 411
Publishing and Subscribing......Page 412
Events and Delegates......Page 413
Solving Delegate Problems with Events......Page 420
The event Keyword......Page 421
Using Anonymous Methods......Page 425
Lambda Expressions......Page 426
Summary......Page 427
Test Your Knowledge: Quiz......Page 428
Test Your Knowledge: Exercises......Page 429
Creating a Simple Windows Form......Page 430
Using the Visual Studio Designer......Page 431
Creating a Real-World Application......Page 437
Creating the Basic UI Form......Page 438
Populating the TreeView Controls......Page 441
TreeNode objects......Page 442
Recursing through the subdirectories......Page 445
Getting the files in the directory......Page 447
Clicking the source TreeView......Page 448
Expanding a directory......Page 449
Clicking the target TreeView......Page 451
Implementing the Copy button event......Page 452
Handling the Delete button event......Page 456
Source Code......Page 457
Summary......Page 465
Test Your Knowledge: Quiz......Page 466
Test Your Knowledge: Exercises......Page 467
Windows Presentation Foundation......Page 468
Your First WPF Application......Page 469
WPF Differences from Windows Forms......Page 473
Using Resources......Page 476
Animations......Page 478
Triggers and Storyboards......Page 479
Animations As Resources......Page 482
C# and WPF......Page 486
Grids and Stack Panels......Page 487
Defining ListBox styles......Page 489
Triggers and animations......Page 490
Adding Data......Page 492
Instantiating objects declaratively......Page 493
Defining the ListBox......Page 494
Event Handling......Page 496
The Complete XAML File......Page 497
Summary......Page 500
Test Your Knowledge: Exercises......Page 502
ADO.NET and Relational Databases......Page 503
Installing the Northwind Database......Page 504
Tables, Records, and Columns......Page 507
Declarative Referential Integrity......Page 508
SQL......Page 509
Rows......Page 511
Getting Started with ADO.NET......Page 512
Summary......Page 515
Test Your Knowledge: Quiz......Page 516
Test Your Knowledge: Exercises......Page 517
Querying In-Memory Data......Page 518
Anonymous Types and Implicitly Typed Variables......Page 523
Lambda Expressions......Page 525
Ordering and Joining......Page 526
Using LINQ with SQL......Page 531
Using the Object Relational Designer......Page 534
Summary......Page 539
Test Your Knowledge: Quiz......Page 540
Test Your Knowledge: Exercises......Page 541
Quiz Solutions......Page 543
Exercise Solution......Page 544
Quiz Solutions......Page 545
Exercise Solutions......Page 546
Quiz Solutions......Page 547
Exercise Solutions......Page 550
Quiz Solutions......Page 554
Exercise Solutions......Page 556
Quiz Solutions......Page 560
Exercise Solutions......Page 561
Quiz Solutions......Page 566
Exercise Solutions......Page 567
Quiz Solutions......Page 569
Exercise Solutions......Page 570
Quiz Solutions......Page 577
Exercise Solutions......Page 578
Quiz Solutions......Page 582
Exercise Solutions......Page 583
Quiz Solutions......Page 587
Exercise Solutions......Page 588
Quiz Solutions......Page 595
Exercise Solutions......Page 596
Quiz Solutions......Page 601
Exercise Solutions......Page 602
Quiz Solutions......Page 611
Exercise Solutions......Page 612
Quiz Solutions......Page 619
Exercise Solutions......Page 620
Quiz Solutions......Page 630
Exercise Solutions......Page 631
Quiz Solutions......Page 638
Exercise Solutions......Page 639
Quiz Solutions......Page 646
Exercise Solutions......Page 647
Quiz Solutions......Page 651
Exercise Solutions......Page 652
Quiz Solutions......Page 659
Exercise Solutions......Page 660
Quiz Solutions......Page 663
Exercise Solutions......Page 664
Quiz Solutions......Page 669
Exercise Solutions......Page 670
Index......Page 675