You are previewing Learning C# 2005, 2nd Edition.
O'Reilly logo
Learning C# 2005, 2nd Edition

Book Description

If you're a novice programmer and you want to learn C#, therearen't many books that will guide you. Most C# books are written forexperienced C++ and Java programmers. That's why Jesse Liberty, author ofthe best-selling books Programming C# andProgramming ASP.NET , has written an entry-levelguide to C#.

Written in a warm and friendly manner, LearningC# assumes no prior programming experience, and provides athorough introduction to Microsoft's premier .NET language. The book helpsyou build a solid foundation in .NET, and shows you how to apply yourskills through the use of dozens of tested examples. You'll learn aboutthe syntax and structure of the C# language, including operators, classesand interfaces, structs, arrays, and strings.

Better yet, this updated edition of LearningC# has been completely revised to include the latest additionsto the C# language plus a variety of learning aids to help lock-in newknowledge and skills. Here's what's new:

  • Extensive revisions to the text and examples to reflect C# 2005and .NET 2.0 changes

  • An introduction to Visual Studio 2005, the most popular toolfor building Windows and web applications

  • More than 200 questions and fully debugged programmingexercises with solutions

  • A greater emphasis on event handling

  • New coverage of generics, generic collections, partial classes,anonymous methods and more.

  • By the time you've finished Learning C# ,you'll be ready to move on to a more advanced programming guide that willhelp you create large-scale web and Windows applications.

    Whether you have a little object-oriented programming experience oryou are new to programming altogether, Learning C#will set you firmly on your way to mastering the essentials of the C#language.

    Table of Contents

    1. Learning C# 2005
      1. Preface
        1. About This Book
        2. Who This Book Is For
        3. How the Book Is Organized
        4. Conventions Used in This Book
        5. Using Code Examples
        6. Support
        7. We’d Like to Hear from You
        8. Safari® Enabled
        9. Acknowledgments
          1. Jesse Liberty
          2. Brian MacDonald
      2. 1. C# and .NET Programming
        1. C# 2005 and .NET 2.0
        2. The .NET Platform
        3. The .NET 2.0 Framework
        4. The C# Language
        5. The Structure of C# Applications
        6. The Development Environment
        7. What’s in a Program?
        8. Your First Program: Hello World
        9. The Compiler
        10. Examining Your First Program
        11. Summary
        12. Quiz
        13. Exercise
      3. 2. Visual Studio 2005
        1. Before You Read Further
        2. Start Page
        3. Projects and Solutions
          1. Web Sites
          2. Templates
        4. Inside the Integrated Development Environment
        5. Building and Running
        6. Menus and Toolbars
          1. File Menu
          2. Edit Menu
            1. Cycle Clipboard Ring
            2. Find and Replace
            3. Go To ...
            4. Find All References
            5. Insert File As Text ...
            6. Advanced
            7. Incremental search
            8. Bookmarks
            9. Outlining
            10. IntelliSense
          3. View Menu
            1. Class View
            2. Code Definition
            3. Error List
            4. Output
            5. Properties
            6. Task List
            7. Toolbox
            8. Other windows
          4. Refactor Menu
          5. Project Menu
          6. Build Menu
          7. Debug Menu
          8. Data Menu
          9. Format Menu
          10. Tools Menu
            1. Connect To Device
            2. Connect To Database
            3. Code Snippets Manager
            4. Choose Toolbox Items
            5. External Tools
            6. Performance Tools
            7. Import and Export Settings
            8. Options
          11. Window Menu
          12. Help Menu
        7. Summary
        8. Quiz
        9. Exercise
      4. 3. C# Language Fundamentals
        1. Statements
        2. Types
          1. Numeric Types
          2. Non-Numeric Types: char and bool
          3. Types and Compiler Errors
        3. Variables
        4. Definite Assignment
        5. Constants
          1. Literal Constants
          2. Symbolic Constants
          3. Enumerations
        6. Strings
        7. Expressions
        8. Whitespace
        9. Summary
        10. Quiz
        11. Exercises
      5. 4. Operators
        1. The Assignment Operator (=)
        2. Mathematical Operators
          1. Simple Arithmetical Operators (+, -, *, / )
          2. The modulus Operator (%)
        3. Increment and Decrement Operators
          1. Calculate and Reassign Operators
          2. Increment or Decrement by 1
          3. The Prefix and Postfix Operators
        4. Relational Operators
          1. Use of Logical Operators with Conditionals
          2. The Conditional Operator
          3. Operator Precedence
        5. Summary
        6. Quiz
        7. Exercises
      6. 5. Branching
        1. Unconditional Branching Statements
        2. Conditional Branching Statements
          1. if Statements
          2. Single-Statement if Blocks
          3. Short-Circuit Evaluation
          4. if ... else Statements
          5. Nested if Statements
          6. switch Statements
          7. Falling-Through and Jumping-to Cases
          8. Switch on string Statements
        3. Iteration (Looping) Statements
          1. Creating Loops with goto
          2. The while Loop
          3. The do ... while Loop
          4. The for Loop
            1. Controlling a for loop with the modulus operator
            2. Breaking out of a for loop
            3. The continue statement
            4. Optional for loop header elements
            5. The while (true) construct
        4. Summary
        5. Quiz
        6. Exercises
      7. 6. Object-Oriented Programming
        1. Creating Models
        2. Classes and Objects
        3. Defining a Class
        4. Class Relationships
        5. The Three Pillars of Object-Oriented Programming
          1. Encapsulation
          2. Specialization
          3. Polymorphism
        6. Object-Oriented Analysis and Design
        7. Summary
        8. Quiz
        9. Exercises
      8. 7. Classes and Objects
        1. Defining Classes
          1. Instantiating Objects
          2. Creating a Time Class
          3. Access Modifiers
        2. Method Arguments
        3. Constructors
        4. Initializers
        5. The this Keyword
        6. Static and Instance Members
          1. Invoking Static Methods
          2. Using Static Fields
        7. Destroying Objects
        8. Memory Allocation: The Stack Versus the Heap
        9. Summary
        10. Quiz
        11. Exercises
      9. 8. Inside Methods
        1. Overloading Methods
        2. Encapsulating Data with Properties
          1. The get Accessor
          2. The set Accessor
        3. Returning Multiple Values
          1. Passing Value Types by Reference
          2. out Parameters and Definite Assignment
        4. Summary
        5. Quiz
        6. Exercises
      10. 9. Basic Debugging
        1. Setting a Breakpoint
          1. Using the Debug Menu to Set Your Breakpoint
          2. Setting Conditions and Hit Counts
        2. Examining Values: The Autos and Locals Windows
        3. Set Your Watch
        4. The Call Stack
        5. Summary
        6. Quiz
        7. Exercises
      11. 10. Arrays
        1. Using Arrays
          1. Declaring Arrays
          2. Understanding Default Values
          3. Accessing Array Elements
        2. The foreach Statement
        3. Initializing Array Elements
        4. The params Keyword
        5. Multidimensional Arrays
          1. Rectangular Arrays
          2. Jagged Arrays
        6. Array Methods
        7. Sorting Arrays
        8. Summary
        9. Quiz
        10. Exercises
      12. 11. Inheritance and Polymorphism
        1. Specialization and Generalization
        2. Inheritance
          1. Implementing Inheritance
          2. Calling Base Class Constructors
          3. Controlling Access
        3. Polymorphism
          1. Creating Polymorphic Types
          2. Versioning with new and override
        4. Abstract Classes
        5. Sealed Classes
        6. The Root of All Classes: Object
        7. Boxing and Unboxing Types
          1. Boxing Is Implicit
          2. Unboxing Must Be Explicit
          3. Avoiding Boxing with Generics
        8. Summary
        9. Quiz
        10. Exercises
      13. 12. Operator Overloading
        1. Using the operator Keyword
        2. Creating Useful Operators
        3. The Equals Operator
        4. Conversion Operators
        5. Summary
        6. Quiz
        7. Exercises
      14. 13. Interfaces
        1. Implementing an Interface
          1. Defining the Interface
          2. Implementing the Interface on the Client
        2. Implementing More than One Interface
        3. Casting to an Interface
        4. The is and as Operators
        5. Extending Interfaces
        6. Combining Interfaces
        7. Overriding Interface Implementations
        8. Explicit Interface Implementation
        9. Summary
        10. Quiz
        11. Exercises
      15. 14. Generics and Collections
        1. Generics
        2. Collection Interfaces
        3. Creating Your Own Collections
          1. Indexers and Assignment
          2. Indexing on Other Values
          3. Generic Collection Interfaces
          4. The IEnumerable<T> Interface
        4. Framework Generic Collections
          1. Generic Lists: List<T>
            1. Creating objects that can be sorted by the generic list
            2. Controlling how elements in a generic collection are sorted by implementing IComparer<T>
          2. Generic Queues
          3. Generic Stacks
          4. Dictionaries
        5. Summary
        6. Quiz
        7. Exercises
      16. 15. Strings
        1. Creating Strings
          1. String Literals
          2. Escape Characters
          3. Verbatim Strings
          4. The ToString( ) Method
        2. Manipulating Strings
          1. Comparing Strings
          2. Concatenating Strings
          3. Copying Strings
          4. Testing for Equality
          5. Other Useful String Methods
          6. Finding Substrings
          7. Splitting Strings
          8. The StringBuilder Class
        3. Regular Expressions
        4. The Regex Class
        5. Summary
        6. Quiz
        7. Exercises
      17. 16. Throwing and Catching Exceptions
        1. Bugs, Errors, and Exceptions
        2. Throwing Exceptions
        3. Searching for an Exception Handler
        4. The throw Statement
        5. The try and catch Statements
        6. How the Call Stack Works
        7. Creating Dedicated catch Statements
        8. The finally Statement
        9. Exception Class Methods and Properties
        10. Custom Exceptions
        11. Summary
        12. Quiz
        13. Exercises
      18. 17. Delegates and Events
        1. Delegates
          1. Using Delegates to Specify Methods at Runtime
        2. Multicasting
        3. Events
          1. Publishing and Subscribing
          2. Events and Delegates
          3. Solving Delegate Problems with Events
          4. The event Keyword
        4. Using Anonymous Methods
        5. Summary
        6. Quiz
        7. Exercises
      19. 18. Creating Windows Applications
        1. Creating a Simple Windows Form
          1. Using the Visual Studio Designer
          2. The partial Keyword
        2. Creating a Real-World Application
          1. Creating the Basic UI Form
          2. Populating the TreeView Controls
            1. TreeNode objects
            2. Recursing through the subdirectories
            3. Getting the files in the directory
          3. Handling TreeView Events
            1. Clicking the source TreeView
            2. Expanding a directory
            3. Clicking the target TreeView
            4. Handling the Clear button event
          4. Implementing the Copy Button Event
            1. Sorting the list of selected files
          5. Handling the Delete Button Event
        3. XML Documentation Comments
        4. Summary
        5. Quiz
        6. Exercises
      20. 19. Programming ASP.NET Applications
        1. Understanding Web Forms
        2. Web Form Events
          1. Postback Versus Non-Postback Events
          2. State
        3. Creating a Web Form
          1. Code-Behind Files
          2. Enabling Debugging
        4. Adding Controls
        5. Server Controls
        6. Data Binding
        7. Adding Controls and Events
        8. Summary
        9. Quiz
        10. Exercises
      21. A. Answers to Quizzes and Exercises
        1. Chapter 1: C# and .NET Programming
          1. Quiz
          2. Exercise
        2. Chapter 2: Visual Studio 2005
          1. Quiz
          2. Exercises
        3. Chapter 3: C# Language Fundamentals
          1. Quiz
          2. Exercises
        4. Chapter 4: Operators
          1. Quiz
          2. Exercises
        5. Chapter 5: Branching
          1. Quiz
          2. Exercises
        6. Chapter 6: Object-Oriented Programming
          1. Quiz
          2. Exercises
        7. Chapter 7: Classes and Objects
          1. Quiz
          2. Exercises
        8. Chapter 8: Inside Methods
          1. Quiz
          2. Exercises
        9. Chapter 9: Basic Debugging
          1. Quiz
          2. Exercises
        10. Chapter 10: Arrays
          1. Quiz
          2. Exercises
        11. Chapter 11: Inheritance and Polymorphism
          1. Quiz
          2. Exercises
        12. Chapter 12: Operator Overloading
          1. Quiz
          2. Exercises
        13. Chapter 13: Interfaces
          1. Quiz
          2. Exercises
        14. Chapter 14: Generics and Collections
          1. Quiz
          2. Exercises
        15. Chapter 15: Strings
          1. Quiz
          2. Exercises
        16. Chapter 16: Throwing and Catching Exceptions
          1. Quiz
          2. Exercises
        17. Chapter 17: Delegates and Events
          1. Quiz
          2. Exercises
        18. Chapter 18: Creating Windows Applications
          1. Quiz
          2. Exercises
        19. Chapter 19: Programming ASP.NET Applications
          1. Quiz
          2. Exercises
      22. Index
      23. Colophon