C# 3.0: The Complete Reference (3rd Edition)

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"

The Most Comprehensive C# Resource AvailableWith its support for Language-Integrated Query (LINQ), C# 3.0 has revolutionized C# programming, and bestselling author Herb Schildt has updated and expanded his classic programming reference to cover it. Using carefully crafted explanations, insider tips, and hundreds of examples, this book presents in-depth coverage of all aspects of C#, including its keywords, syntax, and core libraries. Of course, details on the new C# 3.0 features, such as LINQ, lambda expressions, implicitly typed variables, and anonymous types are included.Essential for every C# programmer, this comprehensive guide is written in the clear, crisp, uncompromising style that has made Herb the choice of millions worldwide. Whether you are a novice programmer or a seasoned pro, the answers to all of your C# questions can be found in this definitive resource.Coverage includes:Data types and operatorsControl statements Classes and objectsConstructors, destructors, and methodsInterfaces, arrays, enumerations, and structuresMethod and operator overloadingInheritance and virtual methodsReflection and runtime type IDException handling Delegates, properties, events, and indexersAttributes MultithreadingGenericsLINQ (Language-Integrated Query)Lambda expressionsAnonymous typesExtension methodsImplicitly typed variablesI/O, networking, and collectionsThe preprocessor and much, much more

Author(s): Herbert Schildt
Edition: 3
Year: 2008

Language: English
Pages: 912

Contents......Page 8
Special Thanks......Page 22
Preface......Page 24
Part I: The C# Language......Page 28
C#’s Family Tree......Page 30
How C# Relates to the .NET Framework......Page 34
How the Common Language Runtime Works......Page 35
Managed vs. Unmanaged Code......Page 36
Object-Oriented Programming......Page 38
A First Simple Program......Page 40
A Small Variation......Page 49
A Second Simple Program......Page 50
Another Data Type......Page 52
Two Control Statements......Page 53
Using Code Blocks......Page 56
Semicolons, Positioning, and Indentation......Page 58
The C# Keywords......Page 59
Identifiers......Page 60
The .NET Framework Class Library......Page 61
C#’s Value Types......Page 62
Integers......Page 63
Floating-Point Types......Page 65
The decimal Type......Page 67
Characters......Page 68
The bool Type......Page 69
Some Output Options......Page 70
Literals......Page 73
A Closer Look at Variables......Page 76
The Scope and Lifetime of Variables......Page 79
Type Conversion and Casting......Page 82
Type Conversion in Expressions......Page 86
Arithmetic Operators......Page 90
Relational and Logical Operators......Page 94
The Assignment Operator......Page 98
The Bitwise Operators......Page 100
The ? Operator......Page 109
Spacing and Parentheses......Page 110
Operator Precedence......Page 111
The if Statement......Page 112
The switch Statement......Page 115
The for Loop......Page 119
The while Loop......Page 126
The do-while Loop......Page 128
Using break to Exit a Loop......Page 129
Using continue......Page 131
The goto......Page 132
Class Fundamentals......Page 136
How Objects Are Created......Page 141
Reference Variables and Assignment......Page 142
Methods......Page 143
Constructors......Page 153
The new Operator Revisited......Page 157
Garbage Collection and Destructors......Page 158
The this Keyword......Page 160
Arrays......Page 164
Multidimensional Arrays......Page 168
Jagged Arrays......Page 171
Assigning Array References......Page 173
Using the Length Property......Page 175
Implicitly Typed Arrays......Page 178
The foreach Loop......Page 179
Strings......Page 183
Controlling Access to Class Members......Page 192
Pass References to Methods......Page 199
Use ref and out Parameters......Page 203
Use a Variable Number of Arguments......Page 209
Return Objects......Page 212
Method Overloading......Page 215
Overload Constructors......Page 221
Object Initializers......Page 226
The Main( ) Method......Page 227
Recursion......Page 229
Understanding static......Page 232
Static Classes......Page 238
Operator Overloading Fundamentals......Page 240
Handling Operations on C# Built-in Types......Page 247
Overloading the Relational Operators......Page 251
Overloading true and false......Page 253
Overloading the Logical Operators......Page 256
Conversion Operators......Page 262
Operator Overloading Tips and Restrictions......Page 266
Another Example of Operator Overloading......Page 267
Indexers......Page 272
Properties......Page 281
Use Access Modifiers with Accessors......Page 288
Using Indexers and Properties......Page 291
Inheritance Basics......Page 296
Member Access and Inheritance......Page 299
Constructors and Inheritance......Page 303
Inheritance and Name Hiding......Page 309
Creating a Multilevel Hierarchy......Page 312
When Are Constructors Called?......Page 315
Base Class References and Derived Objects......Page 316
Virtual Methods and Overriding......Page 321
Using Abstract Classes......Page 328
The object Class......Page 332
Interfaces......Page 338
Using Interface References......Page 343
Interface Properties......Page 345
Interface Indexers......Page 347
Interfaces Can Be Inherited......Page 349
Explicit Implementations......Page 350
Structures......Page 353
Enumerations......Page 359
The System.Exception Class......Page 364
Exception Handling Fundamentals......Page 365
The Consequences of an Uncaught Exception......Page 368
Exceptions Let You Handle Errors Gracefully......Page 370
Using Multiple catch Clauses......Page 371
Catching All Exceptions......Page 372
Nesting try Blocks......Page 373
Throwing an Exception......Page 374
Using finally......Page 376
A Closer Look at the Exception Class......Page 378
Deriving Exception Classes......Page 381
Catching Derived Class Exceptions......Page 385
Using checked and unchecked......Page 387
C#’s I/O Is Built Upon Streams......Page 390
The Stream Classes......Page 391
Console I/O......Page 394
FileStream and Byte-Oriented File I/O......Page 398
Character-Based File I/O......Page 405
Redirecting the Standard Streams......Page 408
Reading and Writing Binary Data......Page 410
Random Access Files......Page 417
Using MemoryStream......Page 419
Using StringReader and StringWriter......Page 421
Converting Numeric Strings to Their Internal Representation......Page 423
Delegates......Page 426
Anonymous Functions......Page 435
Anonymous Methods......Page 436
Lambda Expressions......Page 440
Events......Page 446
Use Anonymous Methods and Lambda Expressions with Events......Page 456
.NET Event Guidelines......Page 457
Applying Events: A Case Study......Page 460
Namespaces......Page 464
The Preprocessor......Page 478
Assemblies and the internal Access Modifier......Page 484
Runtime Type Identification......Page 486
Reflection......Page 490
Using Reflection......Page 492
Attributes......Page 510
Three Built-in Attributes......Page 518
What Are Generics?......Page 522
A Simple Generics Example......Page 523
A Generic Class with Two Type Parameters......Page 529
Constrained Types......Page 530
Creating a Default Value of a Type Parameter......Page 549
Generic Structures......Page 550
Creating a Generic Method......Page 551
Generic Delegates......Page 554
Generic Interfaces......Page 557
Comparing Instances of a Type Parameter......Page 561
Generic Class Hierarchies......Page 564
Overriding Virtual Methods in a Generic Class......Page 567
Overloading Methods That Use Type Parameters......Page 569
How Generic Types Are Instantiated......Page 570
Final Thoughts on Generics......Page 571
What Is LINQ?......Page 572
LINQ Fundamentals......Page 573
Filter Values with where......Page 578
Sort Results with orderby......Page 579
A Closer Look at select......Page 583
Use Nested from Clauses......Page 587
Group Results with group......Page 588
Use into to Create a Continuation......Page 590
Use let to Create a Variable in a Query......Page 592
Join Two Sequences with join......Page 593
Anonymous Types......Page 596
Create a Group Join......Page 598
The Query Methods......Page 601
Deferred vs. Immediate Query Execution......Page 607
Expression Trees......Page 608
Extension Methods......Page 609
Unsafe Code......Page 612
Nullable Types......Page 625
Partial Types......Page 630
Partial Methods......Page 631
Miscellaneous Keywords......Page 632
Part II: Exploring the C# Library......Page 640
The Members of System......Page 642
The Math Class......Page 644
The .NET Structures Corresponding to the Built-in Value Types......Page 650
The Array Class......Page 668
BitConverter......Page 681
Generating Random Numbers with Random......Page 683
Memory Management and the GC Class......Page 684
The IComparable and IComparable Interfaces......Page 686
The ICloneable Interface......Page 687
IFormatProvider and IFormattable......Page 689
Strings in C#......Page 690
The String Class......Page 691
Formatting......Page 711
Using String.Format( ) and ToString( ) to Format Data......Page 715
Creating a Custom Numeric Format......Page 719
Formatting Date and Time......Page 722
Formatting Enumerations......Page 727
Multithreading Fundamentals......Page 730
The Thread Class......Page 731
Determining When a Thread Ends......Page 737
Passing an Argument to a Thread......Page 740
Thread Priorities......Page 742
Synchronization......Page 744
Thread Communication Using Wait( ), Pulse( ), and PulseAll( )......Page 750
Deadlock and Race Conditions......Page 754
Using MethodImplAttribute......Page 755
Using a Mutex and a Semaphore......Page 757
Using Events......Page 764
The Interlocked Class......Page 766
Terminating a Thread......Page 768
Determining a Thread’s State......Page 772
Using the Main Thread......Page 773
Starting a Separate Task......Page 774
Collections Overview......Page 776
The Non-Generic Collections......Page 777
Storing Bits with BitArray......Page 798
The Generic Collections......Page 801
Storing User-Defined Classes in Collections......Page 826
Implementing IComparable......Page 828
Using an IComparer......Page 832
Accessing a Collection via an Enumerator......Page 835
Implementing IEnumerable and IEnumerator......Page 838
Using Iterators......Page 840
Collection Initializers......Page 846
The System.Net Members......Page 848
Internet Access Fundamentals......Page 850
Handling Network Errors......Page 857
The Uri Class......Page 860
Accessing Additional HTTP Response Information......Page 861
MiniCrawler: A Case Study......Page 866
Using WebClient......Page 869
A Brief History of Windows Programming......Page 874
How Windows Interacts with the User......Page 875
A Skeletal Form-Based Windows Program......Page 876
Adding a Button......Page 879
Handling Messages......Page 880
Using a Message Box......Page 883
Adding a Menu......Page 886
The XML Comment Tags......Page 894
Compiling Documentation Comments......Page 895
An XML Documentation Example......Page 896
A......Page 898
C......Page 899
D......Page 901
F......Page 902
H......Page 903
I......Page 904
L......Page 905
M......Page 906
O......Page 907
R......Page 908
S......Page 909
T......Page 911
W......Page 912
Z......Page 913