You are previewing Learning C#.
O'Reilly logo
Learning C#

Book Description

Most C# books are written for experienced C++ and Java programmers. If you're a novice programmer, or you have experience in VB6 or other procedural programming languages, and you want to learn C#, until now you've been out of luck. That's why Jesse Liberty, author of the best-selling books Programming C# and Programming ASP.NET, has written an entry-level guide to C#. Written in a warm and friendly manner, this book assumes no prior programming experience, and provides an easy introduction to Microsoft's premier .NET language. Learning C# is a complete introduction to C# and object-oriented programming. Learning C# will help you build a solid foundation in .NET, and show how to apply your skills by using dozens of tested examples. Learning C# introduces Visual Studio .NET, a tool set for building Windows and Web applications. You'll learn about the syntax and structure of the C# language, including operators, classes and interfaces, structs, arrays, and strings. Liberty then demonstrates how to develop various kinds of applications--including those that work with databases--and web services. By the time you've finished Learning C# you'll be ready to move on to a more advanced programming guide that will help you create large-scale web and Windows applications. Whether you have a little object-oriented programming experience or you 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#
    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. Support
      6. We’d Like to Hear from You
      7. Acknowledgments
    2. 1. C# and .NET Programming
      1. C# and .NET
      2. The .NET Platform
      3. The .NET Framework
      4. The C# Language
      5. The Structure of C# Applications
      6. The Development Environment
    3. 2. Getting Started with C#
      1. What’s in a Program?
      2. Your First Program: Hello World
        1. The Compiler
      3. Examining Your First Program
        1. Line-by-Line Analysis
    4. 3. 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
      6. Encapsulation
      7. Specialization
      8. Polymorphism
      9. Object-Oriented Analysis and Design
    5. 4. Visual Studio .NET
      1. Start Page
        1. Projects and Solutions
        2. Templates
      2. Inside the Integrated Development Environment (IDE)
        1. Layout
      3. IntelliSense
      4. Building and Running
      5. For More Information
    6. 5. C# Language Fundamentals
      1. Types
        1. Numeric Types
        2. Non-Numeric Types: char and bool
        3. Types and Compiler Errors
      2. Variables
      3. Definite Assignment
      4. Constants
        1. Literal Constants
        2. Symbolic Constants
        3. Enumerations
      5. Strings
      6. Statements
      7. Expressions
      8. Whitespace
    7. 6. Branching
      1. Unconditional Branching Statements
      2. Conditional Branching Statements
        1. if Statements
        2. Single Statement if Blocks
        3. if . . . else Statements
        4. Nested if Statements
        5. Switch Statements
        6. Falling Through and Jumping to Cases
        7. 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. Breaking out of a for loop
          2. The continue statement
          3. Optional for loop header elements
          4. The while (true) construct
    8. 7. Operators
      1. The Assignment Operator (=)
      2. Mathematical Operators
        1. Simple Arithmetical Operators (+, -, *, / )
        2. Using the modulus Operator (%) to Return Remainders
      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. Short-Circuit Evaluation
        4. Operator Precedence
    9. 8. Classes and Objects
      1. Defining Classes
        1. Instantiating Objects
          1. Classes versus objects
        2. Memory Allocation: The Stack Versus the Heap
        3. Creating a Time Class
        4. Access Modifiers
      2. Method Arguments
      3. Constructors
      4. Initializers
      5. Copy Constructors
      6. The this Keyword
      7. Static and Instance Members
        1. Invoking Static Methods
        2. Customizing VS.NET to Create a Run Method
        3. Using Static Fields
      8. Destroying Objects
    10. 9. Inside Methods
      1. Overloading Methods
      2. Encapsulating Data with Properties
        1. The get Accessor
        2. The set Accessor
      3. Returning Multiple Values
        1. Passing by Value and by Reference
        2. Out Parameters and Definite Assignment
    11. 10. Basic Debugging
      1. Setting a Breakpoint
        1. Using the Debug Menu to Set Your Breakpoint
        2. Examining Values: The Autos and Locals Windows
        3. Set Your Watch
      2. The Call Stack
    12. 11. Inheritance and Polymorphism
      1. Specialization and Generalization
      2. Inheritance
        1. Implementing Inheritance
        2. Calling Base Class Constructors
        3. Overriding Base Methods
        4. Controlling Access
      3. Polymorphism
        1. Creating Polymorphic Types
          1. Creating polymorphic methods
        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
    13. 12. Operator Overloading
      1. Using the operator Keyword
      2. Creating Useful Operators
      3. Logical Pairs
        1. The Equals Operator
      4. Conversion Operators
    14. 13. Structs
      1. Defining a Struct
        1. No Inheritance
        2. No Initialization
        3. Public Member Data?
    15. 14. Interfaces
      1. Implementing an Interface
      2. Implementing More Than One Interface
      3. Casting to an Interface
        1. The is Operator
        2. The as Operator
      4. Extending Interfaces
      5. Combining Interfaces
      6. Overriding Interface Implementations
      7. Explicit Interface Implementation
    16. 15. Arrays
      1. Arrays
        1. Declaring Arrays
        2. Understanding Default Values
        3. Accessing Array Elements
        4. The foreach Statement
        5. Initializing Array Elements
        6. The params Keyword
      2. Multidimensional Arrays
        1. Rectangular Arrays
        2. Jagged Arrays
      3. System.Array
      4. Indexers
        1. Indexers and Assignment
        2. Indexing on Other Values
    17. 16. Collection Interfaces and Types
      1. The Collection Interfaces
        1. The IEnumerable Interface
        2. Walking Through foreach in a Debugger
      2. Array Lists
      3. Queues
      4. Stacks
      5. Copying from a Collection Type to an Array
    18. 17. 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
    19. 18. Throwing and Catching Exceptions
      1. Throwing Exceptions
      2. Searching for an Exception Handler
      3. The throw Statement
      4. The try and catch Statements
      5. How the Call Stack Works
      6. Creating Dedicated catch Statements
      7. The finally Statement
      8. Exception Class Methods and Properties
      9. Custom Exceptions
    20. 19. Delegates and Events
      1. Delegates
        1. Using Delegates to Specify Methods at Runtime
        2. Static Methods Versus Instance Methods
        3. Static Delegates
        4. Delegates as Properties
      2. Multicasting
      3. Events
        1. Publishing and Subscribing
        2. Events and Delegates
    21. 20. Afterword
      1. Where to Go from Here
      2. Advanced Topics in C#
      3. Web (ASP.NET) Programming
      4. Windows Forms Programming
      5. Other Resources
    22. C# Keywords
    23. Index
    24. Colophon