You are previewing C# Primer Plus.
O'Reilly logo
C# Primer Plus

Book Description

C# Primer Plus teaches the C# programming language and relevant parts of the .NET platform from the ground up, walking you through the basics of object-oriented programming, important programming techniques and problem solving while providing a thorough coverage of C#'s essential elements - such as classes, objects, data types, loops, branching statements, arrays, and namespaces.

In early chapters guided tours take you sightseeing to the main attractions of C# and provide a fast learning-path that enables you to quickly write simple C# programs. Your initial programming skills are then gradually expanded, through the many examples, case studies, illustrations, review questions and programming exercises, to include powerful concepts - like inheritance, polymorphism, interfaces and exception handling, along with C#'s most innovative features - such as properties, indexers, delegates and events.

With C# Primer Plus's dual emphasis on C# as well as fundamental programming techniques, this friendly tutorial will soon make you a proficient C# programmer building Windows applications on the .NET platform.

Table of Contents

  1. Copyright
  2. ABOUT THE AUTHOR
  3. ACKNOWLEDGMENTS
  4. TELL US WHAT YOU THINK!
  5. INTRODUCTION
  6. COMPUTERS AND COMPUTER PROGRAMMING: BASIC CONCEPTS
    1. C# Is an Object-Oriented Programming Language
    2. Hardware
    3. Software
    4. Summary
    5. Review Questions
  7. YOUR FIRST C# PROGRAM
    1. Software Development
    2. The Software Development Process
    3. Algorithms and Pseudocode
    4. The Three Different Types of Errors
    5. Object-Oriented Programming: A First Encounter
    6. Software Reuse
    7. The Assembly, the Basic Unit of Code Reuse in .NET
    8. The .NET Framework Class Library
    9. C#: History and Design Goals
    10. C#'s Background
    11. C#'s Design Goals
    12. What Kind of Programs Can I Write with C#?
    13. The Mechanics of Creating a C# Program
    14. Before Getting Started
    15. Choosing a Text Editor
    16. The Seven Steps to Writing a Simple C# Program
    17. A Brief Source Code Analysis
    18. Note on Syntax Errors and Compilers
    19. Summary
    20. Review Questions
    21. Programming Exercises
  8. A GUIDED TOUR THROUGH C#: PART I
    1. Introduction
    2. Abstraction and Encapsulation
    3. An Interactive Hello World! Program
    4. Summary
    5. Review Questions
    6. Programming Exercises
  9. A GUIDED TOUR THROUGH C#: PART II
    1. Introduction
    2. Essential Elements of SimpleCalculator.cs
    3. Simplifying Your Code with Methods
    4. Methods As Building Blocks: Encapsulating Your Helper Methods with the private keyword.
    5. Summary
    6. Review Questions
    7. Programming Exercises
  10. YOUR FIRST OBJECT-ORIENTED C# PROGRAM
    1. Introduction
    2. Lexical Structure
    3. Some Thoughts on Elevator Simulations
    4. Concepts, Goals and Solutions in an Elevator Simulation Program: Collecting Valuable Statistics for Evaluating an Elevator System
    5. Object-Oriented Programming: A Practical Example
    6. Summary
    7. Review Questions
    8. Programming Exercises
  11. TYPES PART I: THE SIMPLE TYPES
    1. Introduction
    2. Types in C#: An Overview
    3. Simple Types
    4. The Blipos Clock
    5. Summary
    6. Review Questions
    7. Programming Exercises
  12. TYPES PART II: OPERATORS, ENUMERATORS, AND STRINGS
    1. Introduction
    2. Arithmetic Operators and Numerical Expressions
    3. Associativity
    4. Parentheses and Precedence
    5. The Modulus Operator (%)
    6. Unary Operators
    7. Determining the Type of an Expression
    8. Combining Different Types in One Expression
    9. Accessing the Metadata of a Component: A Brief Introduction
    10. Enumerated Constants
    11. Enumerator Operators
    12. Conversions
    13. The Methods of System.Enum
    14. Characters and Text
    15. The char Type
    16. The string type
    17. Summary
    18. Review Questions
    19. Programming Exercises
  13. FLOW OF CONTROL PART I: BRANCHING STATEMENTS AND RELATED CONCEPTS
    1. Introduction to Flow of Control
    2. Branching with the if Statement
    3. Comparison Operators and Boolean Expressions
    4. Nested if Statements
    5. Multibranch if-else Statements
    6. Logical Operators
    7. The Scope of Variables
    8. The goto Statement
    9. The switch Statement
    10. The Conditional Operator
    11. Summary
    12. Review Questions
    13. Programming Exercises
  14. FLOW OF CONTROL PART II: ITERATION STATEMENTS
    1. Traversing, Analyzing, and Generating Sequences of Data
    2. The while Loop Statement
    3. The do-while Loop Statement
    4. The for Loop Statement
    5. The Jump Statements break and continue
    6. Structured Programming and Structured Constructs
    7. Combination Assignment Operators
    8. Nested Iteration Statements
    9. Programming Exercises
    10. Summary
    11. Review Questions
    12. Programming Exercises
  15. ARRAYS PART I: ARRAY ESSENTIALS
    1. Declaring and Defining an Array
    2. Accessing Individual Array Elements
    3. Array Indexes Out of Range
    4. Adjusting for the Zero-Based Array Index
    5. Initializing Arrays
    6. Traversing an Entire Array with the foreach Statement
    7. System.Array Is a Reference Type
    8. Arrays and Equality
    9. Arrays and Methods
    10. A Method to Perform Array Value Equality Comparisons
    11. Command Line Arguments
    12. Using Arrays As Return Values from Methods
    13. Array Elements Referencing Objects
    14. Arrays As Instance Variables in Classes
    15. Summary
    16. Review Questions
    17. Programming Exercises
  16. ARRAYS PART II: MULTIDIMENSIONAL ARRAYS—SEARCHING AND SORTING ARRAYS
    1. Multidimensional Arrays
    2. Arrays of More Than Two Dimensions
    3. The Built-In Methods of System.Array
    4. Special Array Techniques
    5. Searching
    6. Summary
    7. Review Questions
    8. Programming Exercises
  17. CLASS ANATOMY PART I: static CLASS MEMBERS AND METHOD ADVENTURES
    1. The Anatomy of a Class: Overview
    2. Data Members
    3. Function Members
    4. Summary
    5. Review Questions
    6. Programming Exercises
  18. CLASS ANATOMY PART II: OBJECT CREATION AND GARBAGE COLLECTION
    1. Instance Constructors
    2. static Constructors
    3. The readonly Member
    4. Garbage Collection: Automatic Dynamic Memory Management
    5. Summary
    6. Review Questions
    7. Programming Exercises
  19. CLASS ANATOMY PART III: WRITING INTUITIVE CODE
    1. Properties
    2. Indexers: Using Objects Like Arrays
    3. Operator Overloading
    4. User-Defined Implicit and Explicit Conversions
    5. Nested Types
    6. Summary
    7. Review Questions
    8. Programming Exercises
  20. NAMESPACES, COMPILATION UNITS, AND ASSEMBLIES
    1. Defining Your Own Namespaces
    2. The Global Nameless Namespace
    3. Namespaces and Compilation Units
    4. Nested Namespaces
    5. Namespace Syntax
    6. More About the using Directive
    7. Compile Units, Namespaces, and Assemblies
    8. Exploring Assemblies with the Ildasm Utility
    9. Summary
    10. Review Questions
    11. Programming Exercises
  21. INHERITANCE PART I: BASIC CONCEPTS
    1. The Need for Inheritance
    2. Inheritance Fundamentals
    3. Access Modifiers and Inheritance
    4. Derived Class Constructors
    5. Indexers Are Also Inherited and Can Be Overridden
    6. Calling an Overridden Function in the Base Class
    7. Reusing the .NET Framework Class Library with Inheritance
    8. Multiple Levels of Derived Classes
    9. Method Overriding and Overloading Are Different Mechanisms
    10. Summary
    11. Review Questions
    12. Programming Exercises
  22. INHERITANCE PART II: abstract FUNCTIONS, POLYMORPHISM, and INTERFACES
    1. abstract Methods, Properties, Indexers, and Classes
    2. Polymorphism
    3. Losing and Regaining Type Information
    4. System.Object: The Ultimate Base Class
    5. Method hiding
    6. Versioning with the new and override Keywords
    7. Multiple inheritance
    8. Interfaces
    9. Summary
    10. Review Questions
    11. Programming Exercises
  23. STRUCTS
    1. Defining a Struct
    2. Boxing and Unboxing
    3. Creating Structs with and without new
    4. Value Types and Reference Types
    5. Summary
    6. Review Questions
    7. Programming Exercises
  24. EXCEPTION HANDLING
    1. Exception Handling: A Brief Overview
    2. Life without try-catch-finally
    3. The try and catch blocks
    4. Catching the Exception Object Farther up the Function Call Chain
    5. Multiple catch Blocks
    6. The finally Block
    7. Nested try Blocks
    8. throw: Explicitly Throwing Exceptions
    9. Writing Custom Exceptions
    10. Summary
    11. Review Questions
    12. Programming Exercises
  25. DELEGATES AND EVENTS
    1. Delegates
    2. Events
    3. Summary
    4. Review Questions
    5. Programming Exercises
  26. PREPROCESSING, XML DOCUMENTATION, AND ATTRIBUTES
    1. Preprocessor Directives
    2. XML Documentation
    3. Attributes
    4. Summary
    5. Review Questions
    6. Programming Exercises
  27. FILE I/O BASICS
    1. The Need for Files
    2. Stream Basics and File I/O
    3. File I/O Classes: An Overview
    4. The FileInfo Class
    5. Text File Input and Output with StreamReader and StreamWriter
    6. Binary Input and Output with the FileStream Class
    7. Summary
    8. Review Questions
    9. Programming Exercises
  28. RECURSION FUNDAMENTALS
    1. Pending Method Instances of Different Methods
    2. Pending Method Instances of the Same Method
    3. Putting Recursion to Work: Calculating n Factorial
    4. Recursion and Iteration
    5. Binary Search Using Recursion
    6. Summary
    7. Review Questions
    8. Programming Exercises
  29. ANSWERS TO QUIZZES AND EXERCISES
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
    10. Chapter 10
    11. Chapter 11
    12. Chapter 12
    13. Chapter 13
    14. Chapter 14
    15. Chapter 15
    16. Chapter 16
    17. Chapter 17
    18. Chapter 18
    19. Chapter 19
    20. Chapter 20
    21. Chapter 21
    22. Chapter 22
    23. Chapter 23
  30. Index