| |
| |
Preface | |
| |
| |
| |
The C# Language | |
| |
| |
| |
The Creation of C# | |
| |
| |
C#'s Family Tree | |
| |
| |
How C# Relates to the .NET Framework | |
| |
| |
How the Common Language Runtime Works | |
| |
| |
Managed vs. Unmanaged Code | |
| |
| |
| |
An Overview of C# | |
| |
| |
Object-Oriented Programming | |
| |
| |
A First Simple Program | |
| |
| |
Handling Syntax Errors | |
| |
| |
A Small Variation | |
| |
| |
A Second Simple Program | |
| |
| |
Another Data Type | |
| |
| |
Two Control Statements | |
| |
| |
Using Blocks of Code | |
| |
| |
Semicolons, Positioning, and Indentation | |
| |
| |
The C# Keywords | |
| |
| |
Identifiers | |
| |
| |
The C# Class Library | |
| |
| |
| |
Data Types, Literals, and Variables | |
| |
| |
Why Data Types Are Important | |
| |
| |
C#'s Value Types | |
| |
| |
Integers | |
| |
| |
Floating-Point Types | |
| |
| |
The decimal Type | |
| |
| |
Characters | |
| |
| |
The bool Type | |
| |
| |
Some Output Options | |
| |
| |
Literals | |
| |
| |
A Closer Look at Variables | |
| |
| |
The Scope and Lifetime of Variables | |
| |
| |
Type Conversion and Casting | |
| |
| |
Type Conversion in Expressions | |
| |
| |
| |
Operators | |
| |
| |
Arithmetic Operators | |
| |
| |
Relational and Logical Operators | |
| |
| |
The Assignment Operator | |
| |
| |
The Bitwise Operators | |
| |
| |
The ? Operator | |
| |
| |
Spacing and Parentheses | |
| |
| |
Operator Precedence | |
| |
| |
| |
Program Control Statements | |
| |
| |
The if Statement | |
| |
| |
The switch Statement | |
| |
| |
The for Loop | |
| |
| |
The while Loop | |
| |
| |
The do-while Loop | |
| |
| |
The foreach Loop | |
| |
| |
Using break to Exit a Loop | |
| |
| |
Using continue | |
| |
| |
The goto | |
| |
| |
| |
Introducing Classes and Objects | |
| |
| |
Class Fundamentals | |
| |
| |
How Objects Are Created | |
| |
| |
Reference Variables and Assignment | |
| |
| |
Methods | |
| |
| |
Constructors | |
| |
| |
The new Operator Revisited | |
| |
| |
Garbage Collection and Destructors | |
| |
| |
The this Keyword | |
| |
| |
| |
Arrays and Strings | |
| |
| |
Arrays | |
| |
| |
Multidimensional Arrays | |
| |
| |
Jagged Arrays | |
| |
| |
Assigning Array References | |
| |
| |
Using the Length Property | |
| |
| |
The foreach Loop | |
| |
| |
Strings | |
| |
| |
| |
A Closer Look at Methods and Classes | |
| |
| |
Controlling Access to Class Members | |
| |
| |
Pass References to Methods | |
| |
| |
Using ref and out Parameters | |
| |
| |
Using a Variable Number of Arguments | |
| |
| |
Returning Objects | |
| |
| |
Method Overloading | |
| |
| |
Overloading Constructors | |
| |
| |
The Main() Method | |
| |
| |
Recursion | |
| |
| |
Understanding static | |
| |
| |
Static Classes | |
| |
| |
| |
Operator Overloading | |
| |
| |
Operator Overloading Fundamentals | |
| |
| |
Handling Operations on C# Built-In Types | |
| |
| |
Overloading the Relational Operators | |
| |
| |
Overloading true and false | |
| |
| |
Overloading the Logical Operators | |
| |
| |
Conversion Operators | |
| |
| |
Operator Overloading Tips and Restrictions | |
| |
| |
Another Example of Operator Overloading | |
| |
| |
| |
Indexers and Properties | |
| |
| |
Indexers | |
| |
| |
Properties | |
| |
| |
Using Access Modifiers with Accessors | |
| |
| |
Using Indexers and Properties | |
| |
| |
| |
Inheritance | |
| |
| |
Inheritance Basics | |
| |
| |
Member Access and Inheritance | |
| |
| |
Constructors and Inheritance | |
| |
| |
Inheritance and Name Hiding | |
| |
| |
Creating a Multilevel Hierarchy | |
| |
| |
When Are Constructors Called? | |
| |
| |
Base Class References and Derived Objects | |
| |
| |
Virtual Methods and Overriding | |
| |
| |
Using Abstract Classes | |
| |
| |
Using sealed to Prevent Inheritance | |
| |
| |
The object Class | |
| |
| |
| |
Interfaces, Structures, and Enumerations | |
| |
| |
Interfaces | |
| |
| |
Using Interface References | |
| |
| |
Interface Properties | |
| |
| |
Interface Indexers | |
| |
| |
Interfaces Can Be Inherited | |
| |
| |
Name Hiding with Interface Inheritance | |
| |
| |
Explicit Implementations | |
| |
| |
Choosing Between an Interface and an Abstract Class | |
| |
| |
The .NET Standard Interfaces | |
| |
| |
An Interface Case Study | |
| |
| |
Structures | |
| |
| |
Enumerations | |
| |
| |
| |
Exception Handling | |
| |
| |
The System.Exception Class | |
| |
| |
Exception Handling Fundamentals | |
| |
| |
The Consequences of an Uncaught Exception | |
| |
| |
Exceptions Let You Handle Errors Gracefully | |
| |
| |
Using Multiple catch Statements | |
| |
| |
Catching All Exceptions | |
| |
| |
Nesting try Blocks | |
| |
| |
Throwing an Exception | |
| |
| |
Using finally | |
| |
| |
A Closer Look at Exception | |
| |
| |
Deriving Exception Classes | |
| |
| |
Catching Derived Class Exceptions | |
| |
| |
Using checked and unchecked | |
| |
| |
| |
Using I/O | |
| |
| |
C#'s I/O Is Built Upon Streams | |
| |
| |
The Stream Classes | |
| |
| |
Console I/O | |
| |
| |
FileStream and Byte-Oriented File I/O | |
| |
| |
Character-Based File I/O | |
| |
| |
Redirecting the Standard Streams | |
| |
| |
Reading and Writing Binary Data | |
| |
| |
Random Access Files | |
| |
| |
Using MemoryStream | |
| |
| |
Using StringReader and StringWriter | |
| |
| |
Converting Numeric Strings to Their Internal Representation | |
| |
| |
| |
Delegates and Events | |
| |
| |
Delegates | |
| |
| |
Events | |
| |
| |
.NET Event Guidelines | |
| |
| |
Using Anonymous Methods with Events | |
| |
| |
Applying Events: A Case Study | |
| |
| |
| |
Namespaces, the Preprocessor, and Assemblies | |
| |
| |
Namespaces | |
| |
| |
The Preprocessor | |
| |
| |
Assemblies and the internal Access Modifier | |
| |
| |
| |
Runtime Type ID, Reflection, and Attributes | |
| |
| |
Runtime Type Identification | |
| |
| |
Reflection | |
| |
| |
Using Reflection | |
| |
| |
Attributes | |
| |
| |
Three Built-in Attributes | |
| |
| |
| |
Generics | |
| |
| |
What Are Generics? | |
| |
| |
A Simple Generics Example | |
| |
| |
A Generic Class with Two Type Parameters | |
| |
| |
The General Form of a Generic Class | |
| |
| |
Constrained Types | |
| |
| |
Creating a Default Object of a Type Parameter | |
| |
| |
Generic Structures | |
| |
| |
Creating a Generic Method | |
| |
| |
Generic Delegates | |
| |
| |
Generic Interfaces | |
| |
| |
Comparing Instances of a Type Parameter | |
| |
| |
Generic Class Hierarchies | |
| |
| |
Overriding Virtual Methods in a Generic Class | |
| |
| |
Overloading Methods That Use Type Parameters | |
| |
| |
How Generic Types Are Instantiated | |
| |
| |
Some Generic Restrictions | |
| |
| |
Final Thoughts on Generics | |
| |
| |
| |
Unsafe Code, Pointers, Nullable Types, and Miscellaneous Topics | |
| |
| |
Unsafe Code | |
| |
| |
Nullable Types | |
| |
| |
Partial Class Definitions | |
| |
| |
Friend Assemblies | |
| |
| |
Miscellaneous Keywords | |
| |
| |
| |
Exploring the C# Library | |
| |
| |
| |
Exploring the System Namespace | |
| |
| |
The Members of System | |
| |
| |
The Math Class | |
| |
| |
The .NET Structures Corresponding to the Built-in Value Types | |
| |
| |
The Array Class | |
| |
| |
BitConverter | |
| |
| |
Generating Random Numbers with Random | |
| |
| |
Memory Management and the GC Class | |
| |
| |
Object | |
| |
| |
The IComparable and IComparable<T> Interfaces | |
| |
| |
The IConvertible Interface | |
| |
| |
The ICloneable Interface | |
| |
| |
IFormatProvider and IFormattable | |
| |
| |
The IEquatable<T> Interface | |
| |
| |
| |
Strings and Formatting | |
| |
| |
Strings in C# | |
| |
| |
The String Class | |
| |
| |
Formatting | |
| |
| |
Using String.Format() and ToString() to Format Data | |
| |
| |
Creating a Custom Numeric Format | |
| |
| |
Formatting Date and Time | |
| |
| |
Formatting Enumerations | |
| |
| |
| |
Multithreaded Programming | |
| |
| |
Multithreading Fundamentals | |
| |
| |
The Thread Class | |
| |
| |
Determining When a Thread Ends | |
| |
| |
Pass an Argument to a Thread | |
| |
| |
The IsBackground Property | |
| |
| |
Thread Priorities | |
| |
| |
Synchronization | |
| |
| |
Thread Communication Using Wait(), Pulse(), and PulseAll() | |
| |
| |
Using MethodImplAttribute | |
| |
| |
Using a Mutex and a Semaphore | |
| |
| |
Using an Event Synchronization Object | |
| |
| |
The Interlocked Class | |
| |
| |
Terminating a Thread | |
| |
| |
Suspending and Resuming a Thread | |
| |
| |
Determining a Thread's State | |
| |
| |
Using the Main Thread | |
| |
| |
Multithreading Tips | |
| |
| |
Starting a Separate Task | |
| |
| |
| |
Collections, Enumerators, and Iterators | |
| |
| |
Collections Overview | |
| |
| |
The Non-Generic Collections | |
| |
| |
Storing Bits with BitArray | |
| |
| |
The Specialized Collections | |
| |
| |
The Generic Collections | |
| |
| |
Storing User-Defined Classes in Collections | |
| |
| |
Implementing IComparable | |
| |
| |
Using an IComparer | |
| |
| |
Accessing a Collection via an Enumerator | |
| |
| |
Implementing IEnumerable and IEnumerator | |
| |
| |
Using Iterators | |
| |
| |
| |
Networking Through the Internet | |
| |
| |
The System.Net Members | |
| |
| |
Uniform Resource Identifiers | |
| |
| |
Internet Access Fundamentals | |
| |
| |
Handling Network Errors | |
| |
| |
The Uri Class | |
| |
| |
Accessing Additional HTTP Response Information | |
| |
| |
MiniCrawler: A Case Study | |
| |
| |
Using WebClient | |
| |
| |
| |
Applying C# | |
| |
| |
| |
Building Components | |
| |
| |
What Is a Component? | |
| |
| |
What Is a C# Component? | |
| |
| |
IComponent | |
| |
| |
Component | |
| |
| |
A Simple Component | |
| |
| |
Overriding Dispose(bool) | |
| |
| |
Employing the using Statement | |
| |
| |
Containers | |
| |
| |
Are Components the Future of Programming? | |
| |
| |
| |
Creating Form-Based Windows Applications | |
| |
| |
A Brief History of Windows Programming | |
| |
| |
Two Ways to Write a Form-Based Windows Application | |
| |
| |
How Windows Interacts with the User | |
| |
| |
Windows Forms | |
| |
| |
A Skeletal Form-Based Windows Program | |
| |
| |
Adding a Button | |
| |
| |
Handling Messages | |
| |
| |
Using a Message Box | |
| |
| |
Adding a Menu | |
| |
| |
What Next? | |
| |
| |
| |
A Recursive-Descent Expression Parser | |
| |
| |
Expressions | |
| |
| |
Parsing Expressions: The Problem | |
| |
| |
Parsing an Expression | |
| |
| |
Dissecting an Expression | |
| |
| |
A Simple Expression Parser | |
| |
| |
Adding Variables to the Parser | |
| |
| |
Syntax Checking in a Recursive-Descent Parser | |
| |
| |
Some Things to Try | |
| |
| |
| |
XML Comment Quick Reference | |
| |
| |
The XML Comment Tags | |
| |
| |
Compiling XML Documentation | |
| |
| |
An XML Documentation Example | |
| |
| |
Index | |