"It was while teaching numerous seminars on various programming languages that author Daniel Solis realized the immense power diagrams have in explaining programming language concepts. Most people learn quicker and retain information better when the material is presented in a clean, simple, visual format. And that approach is exactly what you’ll find in Illustrated C# 2010. Solis uses concise text and bulleted lists, tables to clarify and summarize language features, as well as his renowned, ubiquitous figures and diagrams. Each language feature is illustrated with a concise and focused code sample for complete clarity. The result is a unique guide that will help you understand and get to work with C# fast.In Illustrated C# 2010, you’ll receive an overview of the .NET platform and the role played by C#, and then you’ll move into exploring the C# language in its entirety, including all the new C# 2010 features right down to the most complex topics involved in C#. If you’re a C++ or VB programmer migrating to C# 2010, this book will be invaluable; the unique visual approach offers a far from lightweight treatment of C# 2010, so even the most experienced programmers will come away with a deeper understanding of the C# language.What youll learnDetails of the C# 2010 language presented in a clear, concise treatment New features in the latest version of .NET, in the author’s unique visual style How C# differs from and is similar to other programming languages, aiding migrating C++ and VB programmers who already know how languages work Who this book is forVisual Basic programmers interested in moving to C# C++ programmers interested in moving to C# Novice programmers interested in learning C# Students in introductory programming classes learning C# "
Author(s): Daniel Solis
Publisher: Apress
Year: 2010
Language: English
Commentary: 1181363714
Pages: 744
Tags: Библиотека;Компьютерная литература;C#;
Prelim......Page 1
Contents at a Glance......Page 6
Contents......Page 7
About the Author......Page 27
Acknowledgments......Page 28
Introduction......Page 29
C# and the .NET Framework......Page 31
Enter Microsoft .NET......Page 32
Components of the .NET Framework......Page 33
Interoperability......Page 34
No COM Required......Page 35
The Base Class Library......Page 36
Compiling to the Common Intermediate Language......Page 37
Compiling to Native Code and Execution......Page 38
Overview of Compilation and Execution......Page 39
The Common Language Runtime......Page 40
The Common Language Infrastructure......Page 41
Common Language Specification (CLS)......Page 42
Review of the Acronyms......Page 43
Overview of C# Programming......Page 45
A Simple C# Program......Page 46
More About SimpleProgram......Page 47
Identifiers and Keywords......Page 48
Naming Conventions......Page 49
Keywords......Page 50
Whitespace......Page 51
Blocks......Page 52
Write......Page 53
WriteLine......Page 54
The Format String......Page 55
Multiple Markers and Values......Page 56
Comments: Annotating the Code......Page 57
Documentation Comments......Page 58
Summary of Comment Types......Page 59
Types, Storage, and Variables......Page 61
A C# Program Is a Set of Type Declarations......Page 62
Instantiating a Type......Page 63
Types of Members......Page 64
Predefined Types......Page 65
More About the Predefined Types......Page 66
User-Defined Types......Page 68
Facts About Stacks......Page 69
The Heap......Page 70
Storing Members of a Reference Type Object......Page 71
Categorizing the C# Types......Page 72
Variable Declarations......Page 73
Automatic Initialization......Page 74
Static Typing and the dynamic Keyword......Page 75
Creating a Nullable Type......Page 76
Assigning to a Nullable Type......Page 78
Classes: The Basics......Page 79
A Class Is an Active Data Structure......Page 80
Programs and Classes: A Quick Example......Page 81
Declaring a Class......Page 82
Fields......Page 83
Declarations with Multiple Fields......Page 84
Methods......Page 85
Creating Variables and Instances of a Class......Page 86
Allocating Memory for the Data......Page 87
Combining the Steps......Page 88
Instance Members......Page 89
Private and Public Access......Page 90
Depicting Public and Private Access......Page 91
Example of Member Access......Page 92
Accessing Members from Inside the Class......Page 93
Accessing Members from Outside the Class......Page 94
Putting It All Together......Page 95
Methods......Page 97
The Structure of a Method......Page 98
Code Execution in the Method Body......Page 99
Local Variables......Page 100
Type Inference and the var Keyword......Page 101
Local Variables Inside Nested Blocks......Page 102
Local Constants......Page 103
Flow of Control......Page 104
Method Invocations......Page 105
Return Values......Page 106
The Return Statement and Void Methods......Page 108
Formal Parameters......Page 110
Actual Parameters......Page 111
An Example of Methods with Positional Input Parameters......Page 112
Value Parameters......Page 113
Reference Parameters......Page 116
Output Parameters......Page 119
Parameter Arrays......Page 122
Expanded Form......Page 123
Summary of Parameter Types......Page 126
Method Overloading......Page 127
Named Parameters......Page 128
Optional Parameters......Page 130
Stack Frames......Page 134
Recursion......Page 136
More About Classes......Page 139
Order of Member Modifiers......Page 140
Instance Class Members......Page 142
Static Fields......Page 143
Example of a Static Field......Page 144
Lifetimes of Static Members......Page 145
Static Function Members......Page 146
Other Static Class Member Types......Page 147
Member Constants......Page 148
Constants Are Like Statics......Page 149
Properties......Page 151
Property Declarations and Accessors......Page 152
A Property Example......Page 153
Using a Property......Page 154
Properties and Associated Fields......Page 155
Performing Other Calculations......Page 157
Read-Only and Write-Only Properties......Page 158
An Example of a Computed, Read-Only Property......Page 159
Properties vs. Public Fields......Page 160
Automatically Implemented Properties......Page 161
Static Properties......Page 162
Instance Constructors......Page 163
Constructors with Parameters......Page 164
Default Constructors......Page 165
Static Constructors......Page 166
Accessibility of Constructors......Page 167
Object Initializers......Page 168
Destructors......Page 170
Calling the Destructor......Page 171
The Standard Dispose Pattern......Page 173
Comparing Constructors and Destructors......Page 174
The readonly Modifier......Page 175
The this Keyword......Page 177
Indexers......Page 178
Indexers and Properties......Page 179
Declaring an Indexer......Page 180
The Indexer set Accessor......Page 181
Declaring the Indexer for the Employee Example......Page 182
Another Indexer Example......Page 184
Indexer Overloading......Page 185
Access Modifiers on Accessors......Page 186
Partial Classes and Partial Types......Page 187
Partial Methods......Page 189
Classes and Inheritance......Page 191
Class Inheritance......Page 192
Accessing the Inherited Members......Page 193
All Classes Are Derived from Class object......Page 194
Hiding Members of a Base Class......Page 195
Base Access......Page 197
Using References to a Base Class......Page 198
Virtual and Override Methods......Page 200
Case 1: Declaring Print with override......Page 202
Case 2: Declaring Print with new......Page 204
Overriding Other Member Types......Page 205
Constructor Execution......Page 206
Constructor Initializers......Page 208
Class Access Modifiers......Page 211
Inheritance Between Assemblies......Page 212
Member Access Modifiers......Page 214
Regions Accessing a Member......Page 215
Private Member Accessibility......Page 216
Internal Member Accessibility......Page 217
Summary of Member Access Modifiers......Page 218
Abstract Members......Page 220
Abstract Classes......Page 222
Example of an Abstract Class and an Abstract Method......Page 223
Another Example of an Abstract Class......Page 224
Sealed Classes......Page 225
Static Classes......Page 226
Extension Methods......Page 227
Expressions and Operators......Page 231
Expressions......Page 232
Literals......Page 233
Integer Literals......Page 234
Real Literals......Page 235
Character Literals......Page 236
String Literals......Page 237
Precedence......Page 239
Associativity......Page 240
Simple Arithmetic Operators......Page 242
The Remainder Operator......Page 243
Relational and Equality Comparison Operators......Page 244
Comparison and Equality Operations......Page 245
Increment and Decrement Operators......Page 247
Conditional Logical Operators......Page 249
Logical Operators......Page 251
Shift Operators......Page 253
Assignment Operators......Page 255
Compound Assignment......Page 256
The Conditional Operator......Page 257
Unary Arithmetic Operators......Page 259
User-Defined Type Conversions......Page 260
Explicit Conversion and the Cast Operator......Page 262
Operator Overloading......Page 263
Restrictions on Operator Overloading......Page 264
Example of Operator Overloading......Page 265
The typeof Operator......Page 266
Other Operators......Page 268
Statements......Page 269
What Are Statements?......Page 270
Expression Statements......Page 271
Flow-of-Control Statements......Page 272
The if Statement......Page 273
The if . . . else Statement......Page 274
The switch Statement......Page 275
A Switch Example......Page 277
More on the switch Statement......Page 278
Switch Labels......Page 279
The while Loop......Page 280
The do Loop......Page 281
The for Loop......Page 283
The Scope of Variables in a for Statement......Page 285
Multiple Expressions in the Initializer and Iteration Expression......Page 286
The break Statement......Page 287
The continue Statement......Page 288
Labels......Page 289
The Scope of Labeled Statements......Page 290
The goto Statement Inside a switch Statement......Page 291
The using Statement......Page 292
Packaging Use of the Resource......Page 293
Example of the using Statement......Page 294
Multiple Resources and Nesting......Page 295
Another Form of the using Statement......Page 296
Other Statements......Page 297
Namespaces and Assemblies......Page 299
Referencing Other Assemblies......Page 300
The mscorlib Library......Page 303
Namespaces......Page 305
Namespace Names......Page 309
More About Namespaces......Page 310
Namespaces Spread Across Files......Page 311
Nesting Namespaces......Page 312
The using Namespace Directive......Page 313
The using Alias Directive......Page 314
The Structure of an Assembly......Page 315
The Identity of an Assembly......Page 317
Strongly Named Assemblies......Page 319
Creating a Strongly Named Assembly......Page 320
Private Deployment of an Assembly......Page 321
Installing Assemblies into the GAC......Page 322
Side-by-Side Execution in the GAC......Page 323
Configuration Files......Page 324
Delayed Signing......Page 325
Exceptions......Page 327
What Are Exceptions?......Page 328
The try Statement......Page 329
Handling the Exception......Page 330
The Exception Classes......Page 331
The catch Clause......Page 333
Examples Using Specific catch Clauses......Page 334
The catch Clauses Section......Page 335
The finally Block......Page 336
Finding a Handler for an Exception......Page 337
Searching Further......Page 338
General Algorithm......Page 339
Example of Searching Down the Call Stack......Page 340
Throwing Exceptions......Page 343
Throwing Without an Exception Object......Page 344
Structs......Page 347
What Are Structs?......Page 348
Structs Are Value Types......Page 349
Assigning to a Struct......Page 350
Instance Constructors......Page 351
Summary of Constructors and Destructors......Page 353
Boxing and Unboxing......Page 354
Additional Information About Structs......Page 355
Enumerations......Page 357
Enumerations......Page 358
Setting the Underlying Type and Explicit Values......Page 360
Implicit Member Numbering......Page 361
Bit Flags......Page 362
The Flags Attribute......Page 365
Example Using Bit Flags......Page 367
More About Enums......Page 369
Arrays......Page 371
Important Details......Page 372
Types of Arrays......Page 373
An Array As an Object......Page 374
Declaring a One-Dimensional Array or a Rectangular Array......Page 375
Instantiating a One-Dimensional or Rectangular Array......Page 376
Accessing Array Elements......Page 377
Explicit Initialization of One-Dimensional Arrays......Page 378
Syntax Points for Initializing Rectangular Arrays......Page 379
Shortcut Syntax......Page 380
Implicitly Typed Arrays......Page 381
Putting It All Together......Page 382
Jagged Arrays......Page 383
Shortcut Instantiation......Page 384
Instantiating a Jagged Array......Page 385
Subarrays in Jagged Arrays......Page 386
Comparing Rectangular and Jagged Arrays......Page 387
The foreach Statement......Page 388
The Iteration Variable Is Read-Only......Page 390
Example with a Rectangular Array......Page 391
Example with a Jagged Array......Page 392
Array Covariance......Page 393
Useful Inherited Array Members......Page 394
The Clone Method......Page 396
Comparing Array Types......Page 398
Delegates......Page 399
What Is a Delegate?......Page 400
Declaring the Delegate Type......Page 402
Creating the Delegate Object......Page 403
Assigning Delegates......Page 405
Combining Delegates......Page 406
Adding Methods to Delegates......Page 407
Removing Methods from a Delegate......Page 408
Invoking a Delegate......Page 409
Delegate Example......Page 410
Invoking Delegates with Return Values......Page 411
Invoking Delegates with Reference Parameters......Page 412
Using Anonymous Methods......Page 413
Return Type......Page 414
params Parameters......Page 415
Outer Variables......Page 416
Extension of Captured Variable’s Lifetime......Page 417
Lambda Expressions......Page 418
Events......Page 421
Events Are Like Delegates......Page 422
An Event Has a Private Delegate......Page 423
Overview of Source Code Components......Page 424
Declaring an Event......Page 425
The Delegate Type and EventHandler......Page 426
Raising an Event......Page 427
Subscribing to an Event......Page 428
Removing Event Handlers......Page 430
Using the EventArgs Class......Page 431
Passing Data by Extending EventArgs......Page 432
Using the Custom Delegate......Page 433
The MyTimerClass Code......Page 436
Event Accessors......Page 438
Interfaces......Page 439
What Is an Interface?......Page 440
Example Using the IComparable Interface......Page 441
Declaring an Interface......Page 444
Implementing an Interface......Page 446
Example with a Simple Interface......Page 447
An Interface Is a Reference Type......Page 448
Using the as Operator with Interfaces......Page 450
Implementing Multiple Interfaces......Page 451
Implementing Interfaces with Duplicate Members......Page 452
References to Multiple Interfaces......Page 454
An Inherited Member As an Implementation......Page 456
Explicit Interface Member Implementations......Page 457
Accessing Explicit Interface Member Implementations......Page 460
Interfaces Can Inherit Interfaces......Page 461
Example of Different Classes Implementing an Interface......Page 462
Conversions......Page 465
What Are Conversions?......Page 466
Implicit Conversions......Page 467
Explicit Conversions and Casting......Page 468
Casting......Page 469
Numeric Conversions......Page 470
Implicit Numeric Conversions......Page 471
The checked and unchecked Operators......Page 472
The checked and unchecked Statements......Page 473
Integral to Integral......Page 474
decimal to Integral......Page 475
float or double to decimal......Page 476
decimal to float or double......Page 477
Reference Conversions......Page 478
Implicit Reference Conversions......Page 479
Explicit Reference Conversions......Page 481
Valid Explicit Reference Conversions......Page 482
Boxing Conversions......Page 484
Boxing Creates a Copy......Page 485
Unboxing Conversions......Page 486
The Unboxing Conversions......Page 487
Constraints on User-Defined Conversions......Page 488
Example of a User-Defined Conversion......Page 489
Example of a Multistep User-Defined Conversion......Page 491
The is Operator......Page 493
The as Operator......Page 494
Generics......Page 495
A Stack Example......Page 496
Generics in C#......Page 498
Continuing with the Stack Example......Page 499
Generic Classes......Page 500
Declaring a Generic Class......Page 501
Creating a Constructed Type......Page 502
Creating Variables and Instances......Page 503
The Stack Example Using Generics......Page 505
Comparing the Generic and Nongeneric Stack......Page 507
Constraints on Type Parameters......Page 508
Where Clauses......Page 509
Constraint Types and Order......Page 510
Generic Methods......Page 511
Declaring a Generic Method......Page 512
Invoking a Generic Method......Page 513
Inferring Types......Page 514
Example of a Generic Method......Page 515
Extension Methods with Generic Classes......Page 516
Generic Structs......Page 517
Generic Delegates......Page 518
Another Generic Delegate Example......Page 520
Generic Interfaces......Page 521
An Example Using Generic Interfaces......Page 522
Generic Interface Implementations Must Be Unique......Page 523
Covariance and Contravariance in Generics......Page 524
Covariance and Contravariance in Interfaces......Page 530
More About Variance......Page 532
Enumerators and Iterators......Page 535
Using the foreach Statement......Page 536
Types of Enumerators......Page 537
Using the IEnumerator Interface......Page 538
Declaring an IEnumerator Enumerator......Page 541
The IEnumerable Interface......Page 543
Example Using IEnumerable and IEnumerator......Page 544
The Noninterface Enumerator......Page 546
The Generic Enumeration Interfaces......Page 548
The IEnumerator Interface......Page 549
The IEnumerable Interface......Page 552
Iterators......Page 554
Iterator Blocks......Page 555
Using an Iterator to Create an Enumerator......Page 556
Using an Iterator to Create an Enumerable......Page 558
Common Iterator Patterns......Page 560
Producing Enumerables and Enumerators......Page 561
Producing Multiple Enumerables......Page 562
Producing Multiple Enumerators......Page 564
Behind the Scenes with Iterators......Page 566
Introduction to LINQ......Page 567
What Is LINQ?......Page 568
LINQ Providers......Page 569
Anonymous Types......Page 570
Query Syntax and Method Syntax......Page 572
Query Variables......Page 574
The Structure of Query Expressions......Page 576
The from Clause......Page 577
The join Clause......Page 579
What Is a Join?......Page 580
The from . . . let . . . where Section in the Query Body......Page 583
The from Clause......Page 584
The let Clause......Page 585
The where Clause......Page 586
The orderby Clause......Page 587
The select . . . group Clause......Page 588
Anonymous Types in Queries......Page 590
The group Clause......Page 591
Query Continuation......Page 593
The Standard Query Operators......Page 594
Signatures of the Standard Query Operators......Page 597
Delegates As Parameters......Page 599
The LINQ Predefined Delegate Types......Page 601
Example Using a Delegate Parameter......Page 602
Example Using a Lambda Expression Parameter......Page 603
Markup Languages......Page 605
XML Basics......Page 606
The XML Classes......Page 608
Creating, Saving, Loading, and Displaying an XML Document......Page 609
Creating an XML Tree......Page 610
Using Values from the XML Tree......Page 611
Adding Nodes and Manipulating XML......Page 614
Working with XML Attributes......Page 616
XProcessingInstruction......Page 620
Using LINQ Queries with LINQ to XML......Page 622
Introduction to Asynchronous Programming......Page 625
Processes, Threads, and Asynchronous Programming......Page 626
Multithreading Considerations......Page 627
The Complexity of Multithreading......Page 628
Parallel Loops......Page 629
The BackgroundWorker Class......Page 632
Example Code Using the BackgroundWorker Class......Page 636
Example of the BackgroundWorker Class in a WPF Program......Page 640
Asynchronous Programming Patterns......Page 643
BeginInvoke and EndInvoke......Page 644
The Wait-Until-Done Pattern......Page 646
The AsyncResult Class......Page 647
The Polling Pattern......Page 648
The Callback Method......Page 650
Calling EndInvoke Inside the Callback Method......Page 651
Timers......Page 654
Preprocessor Directives......Page 657
General Rules......Page 658
The #define and #undef Directives......Page 660
Conditional Compilation......Page 661
The Conditional Compilation Constructs......Page 662
Diagnostic Directives......Page 665
Line Number Directives......Page 666
Region Directives......Page 667
The #pragma warning Directive......Page 668
Reflection and Attributes......Page 669
The Type Class......Page 670
Getting a Type Object......Page 672
What Is an Attribute?......Page 675
Applying an Attribute......Page 676
The Obsolete Attribute......Page 677
The Conditional Attribute......Page 678
Example of the Conditional Attribute......Page 679
Predefined Attributes......Page 680
Multiple Attributes......Page 681
Other Types of Targets......Page 682
Global Attributes......Page 683
Declaring a Custom Attribute......Page 684
Specifying the Constructor......Page 685
Using the Constructor......Page 686
Positional and Named Parameters in Constructors......Page 687
Restricting the Usage of an Attribute......Page 688
The Constructor for AttributeUsage......Page 689
Suggested Practices for Custom Attributes......Page 690
Using the IsDefined Method......Page 691
Using the GetCustomAttributes Method......Page 692
Other Topics......Page 693
Strings......Page 694
Using Class StringBuilder......Page 696
Formatting Numeric Strings......Page 697
The Alignment Specifier......Page 698
The Format Component......Page 699
Standard Numeric Format Specifiers......Page 700
Parsing Strings to Data Values......Page 702
More About the Nullable Types......Page 704
The Null Coalescing Operator......Page 706
Using Nullable User-Defined Types......Page 707
Nullable......Page 708
Method Main......Page 709
Accessibility of Main......Page 710
Documentation Comments......Page 711
Inserting Documentation Comments......Page 712
Using Other XML Tags......Page 713
Nested Types......Page 714
Example of a Nested Class......Page 715
Visibility and Nested Types......Page 716
Interoperating with COM......Page 719
Symbols and Numerics A......Page 723
C......Page 725
D......Page 727
E......Page 728
G......Page 730
I......Page 731
J......Page 732
M......Page 733
O......Page 735
P......Page 736
R......Page 737
S......Page 738
T......Page 740
W......Page 741
Y, Z......Page 742