Sign in
|
Register
|
Mobile
Home
Browse
About us
Help/FAQ
Advanced search
Home
>
Browse
>
Beginner's Guide
>
C# 3.0: A Beginner's Guide
CITATION
Schildt, Herbert
.
C# 3.0: A Beginner's Guide
.
US
: McGraw-Hill Osborne Media, 2008.
Add to Favorites
Email to a Friend
Download Citation
C# 3.0: A Beginner's Guide
Authors:
Herbert Schildt
Published:
August 2008
eISBN:
9780071588317 0071588310
|
ISBN:
9780071588300
Open eBook
Book Description
Table of Contents
Contents
Preface
1 C# Fundamentals
C#’s Family Tree
C: The Beginning of the Modern Age of Programming
The Creation of OOP and C++
The Internet and Java Emerge
The Creation of C#
The Evolution of C#
How C# Relates to the .NET Framework
What Is the .NET Framework?
How the Common Language Runtime Works
Managed vs. Unmanaged Code
The Common Language Specification
Object-Oriented Programming
Encapsulation
Polymorphism
Inheritance
Creating, Compiling, and Running Your First C# Program
Obtain a C# 3.0 Compiler
Using the Visual Studio IDE
Using csc.exe, the C# Command-Line Compiler
The First Example Program Line by Line
Handling Syntax Errors
A Small Variation
Using a Variable
The double Data Type
Try This: Convert Fahrenheit to Celsius
Two Control Statements
The if Statement
The for Loop
Using Blocks of Code
Semicolons and Positioning
Indentation Practices
Try This: Improve the Temperature Conversion Program
The C# Keywords
Identifiers
The C# Class Library
2 Introducing Data Types and Operators
Why Data Types Are Important
C#’s Value Types
Integers
Floating-Point Types
The decimal Type
Characters
The bool Type
Some Output Options
Try This: Talk to Mars
Literals
Hexadecimal Literals
Character Escape Sequences
String Literals
A Closer Look at Variables
Initializing a Variable
Dynamic Initialization
Implicitly Typed Variables
The Scope and Lifetime of Variables
Operators
Arithmetic Operators
Increment and Decrement
Relational and Logical Operators
Short-Circuit Logical Operators
Try This: Display a Truth Table for the Logical Operators
The Assignment Operator
Compound Assignments
Type Conversion in Assignments
Casting Incompatible Types
Operator Precedence
Type Conversion in Expressions
Spacing and Parentheses
Try This: Compute the Regular Payments on a Loan
3 Program Control Statements
Inputting Characters from the Keyboard
The if Statement
Nested ifs
The if-else-if Ladder
The switch Statement
Nested switch Statements
Try This: Start Building a C# Help System
The for Loop
Some Variations on the for Loop
Declaring Loop Control Variables Inside the for Loop
The while Loop
The do-while Loop
Try This: Improve the C# Help System
Use break to Exit a Loop
Use continue
The goto
Try This: Finish the C# Help System
Nested Loops
4 Introducing Classes, Objects, and Methods
Class Fundamentals
The General Form of a Class
Define a Class
How Objects Are Created
Reference Variables and Assignment
Methods
Add a Method to the Vehicle Class
Return from a Method
Return a Value
Use Parameters
Add a Parameterized Method to Vehicle
Try This: Create a Help Class
Constructors
Parameterized Constructors
Add a Constructor to the Vehicle Class
The new Operator Revisited
Garbage Collection and Destructors
Destructors
The this Keyword
5 More Data Types and Operators
Arrays
One-Dimensional Arrays
Try This: Sort an Array
Multidimensional Arrays
Two-Dimensional Arrays
Arrays of Three or More Dimensions
Initialize Multidimensional Arrays
Jagged Arrays
Assign Array References
Use the Length Property with Arrays
Create an Implicitly Typed Array
Try This: Create a Simple Queue Class
The foreach Loop
Strings
Construct a String
Operating on Strings
Arrays of Strings
Strings Are Immutable
The Bitwise Operators
The Bitwise AND, OR, XOR, and NOT Operators
The Shift Operators
Bitwise Compound Assignments
Try This: Create a ShowBits Class
The ? Operator
6 A Closer Look at Methods and Classes
Controlling Access to Class Members
C#’s Access Specifiers
Try This: Improve the SimpleQueue Class
Pass an Object Reference to a Method
How Arguments Are Passed
Using ref and out Parameters
Using ref
Using out
Using a Variable Number of Arguments
Returning Objects
Method Overloading
Overloading Constructors
Invoking an Overloaded Constructor Through this
Try This: Overload the SimpleQueue Constructor
The Main( ) Method
Returning Values from Main( )
Passing Arguments to Main( )
Recursion
Understanding static
Static Constructors and Classes
Try This: The Quicksort
7 Operator Overloading, Indexers, and Properties
Operator Overloading
The General Forms of an Operator Method
Overloading Binary Operators
Overloading Unary Operators
Adding Flexibility
Overloading the Relational Operators
Operator Overloading Tips and Restrictions
Indexers
Multidimensional Indexers
Indexer Restrictions
Properties
Auto-Implemented Properties
Property Restrictions
Use an Access Modifier with an Accessor
Try This: Create a Set Class
8 Inheritance
Inheritance Basics
Member Access and Inheritance
Using Protected Access
Constructors and Inheritance
Calling Base Class Constructors
Inheritance and Name Hiding
Using base to Access a Hidden Name
Try This: Extend the Vehicle Class
Creating a Multilevel Hierarchy
When Are Constructors Called?
Base Class References and Derived Objects
Virtual Methods and Overriding
Why Overridden Methods?
Applying Virtual Methods
Using Abstract Classes
Using sealed to Prevent Inheritance
The object Class
Boxing and Unboxing
9 Interfaces, Structures, and Enumerations
Interfaces
Implementing Interfaces
Using Interface References
Try This: Create a Queue Interface
Interface Properties
Interface Indexers
Interfaces Can Be Inherited
Explicit Implementations
Structures
Enumerations
Initialize an Enumeration
Specifying the Underlying Type of an Enumeration
10 Exception Handling
The System.Exception Class
Exception-Handling Fundamentals
Using try and catch
A Simple Exception Example
A Second Exception Example
The Consequences of an Uncaught Exception
Exceptions Let You Handle Errors Gracefully
Using Multiple catch Clauses
Catching All Exceptions
Try Blocks Can Be Nested
Throwing an Exception
Rethrowing an Exception
Using finally
A Closer Look at Exception
Commonly Used Exceptions
Deriving Exception Classes
Catching Derived Class Exceptions
Try This: Add Exceptions to the Queue Class
Using checked and unchecked
11 Using I/O
C#'s I/O Is Built Upon Streams
Byte Streams and Character Streams
The Predefined Streams
The Stream Classes
The Stream Class
The Byte Stream Classes
The Character Stream Wrapper Classes
Binary Streams
Console I/O
Reading Console Input
Writing Console Output
FileStream and Byte-Oriented File I/O
Opening and Closing a File
Reading Bytes from a FileStream
Writing to a File
Character-Based File I/O
Using StreamWriter
Using a StreamReader
Redirecting the Standard Streams
Try This: Create a File Comparison Utility
Reading and Writing Binary Data
BinaryWriter
BinaryReader
Demonstrating Binary I/O
Random Access Files
Converting Numeric Strings to Their Internal Representation
Try This: Create a Disk-Based Help System
12 Delegates, Events, and Namespaces
Delegates
Use Instance Methods as Delegates
Multicasting
Why Delegates
Anonymous Methods
Events
A Multicast Event Example
Use Anonymous Methods with Events
Namespaces
Declare a Namespace
using
A Second Form of using
Namespaces Are Additive
Namespaces Can Be Nested
The Global Namespace
Try This: Put Set into a Namespace
13 Generics
What Are Generics?
Generics Fundamentals
Generic Types Differ Based on Their Type Arguments
Generics Improve Type Safety
Generic Class with Two Type Parameters
Constrained Types
Use a Base Class Constraint
Use a Constraint to Establish a Relationship Between Two Type Parameters
Use an Interface Constraint
Use the new( ) Constructor Constraint
The Reference Type and Value Type Constraints
Use Multiple Constraints
Create a Default Value of a Type Parameter
Generic Structures
Generic Methods
Using Explicit Type Arguments to Call a Generic Method
Using a Constraint with a Generic Method
Generic Delegates
Generic Interfaces
Try This: Create a Generic Queue
14 Introducing LINQ
What Is LINQ?
LINQ Fundamentals
A Simple Query
A Query Can Be Executed More Than Once
How the Data Types in a Query Relate
The General Form of a Query
Filter Values with where
Sort Results with orderby
A Closer Look at select
Group Results with group
Use into to Create a Continuation
Use let to Create a Variable in a Query
Join Two Sequences with join
Anonymous Types and Object Initializers
Create a Group Join
The Query Methods and Lambda Expressions
The Basic Query Methods
Lambda Expressions
Create Queries by Using the Query Methods
More Query-Related Extension Methods
Deferred vs. Immediate Query Execution
A Closer Look at Extension Methods
A Closer Look at Lambda Expressions
Expression Lambdas
Statement Lambdas
Try This: Use Lambda Expressions to Implement Event Handlers
15 The Preprocessor, RTTI, Nullable Types, and Other Advanced Topics
The Preprocessor
#define
#if and #endif
#else and #elif
#undef
#error
#warning
#line
#region and #endregion
#pragma
Runtime Type Identification
Testing a Type with is
Using as
Using typeof
Nullable Types
The ?? Operator
Nullable Objects and the Relational and Logical Operators
Unsafe Code
A Brief Look at Pointers
The unsafe Keyword
Using fixed
Attributes
The Conditional Attribute
The Obsolete Attribute
Conversion Operators
A Brief Introduction to Collections
Collection Basics
A Collections Case Study: Create a Dynamic Array
Try This: Use the Queue<T> Collection
Other Keywords
The internal Access Modifier
sizeof
lock
readonly
stackalloc
The using Statement
const and volatile
The partial Modifier
yield
extern
What Next?
A: Answers to Self Tests
Chapter 1: C# Fundamentals
Chapter 2: Introducing Data Types and Operators
Chapter 3: Program Control Statements
Chapter 4: Introducing Classes, Objects, and Methods
Chapter 5: More Data Types and Operators
Chapter 6: A Closer Look at Methods and Classes
Chapter 7: Operator Overloading, Indexers, and Properties
Chapter 8: Inheritance
Chapter 9: Interfaces, Structures, and Enumerations
Chapter 10: Exception Handling
Chapter 11: Using I/O
Chapter 12: Delegates, Events, and Namespaces
Chapter 13: Generics
Chapter 14: Introducing LINQ
Chapter 15: The Preprocessor, RTTI, Nullable Types, and Other Advanced Topics
Index