Beginning C# 2008: From Novice to Professional

Book description

This book is for anyone who wants to write good C# 2008 code—even if you have never programmed before.

Writing good code can be a challenge. There are so many options, especially in a language like C#. If you want to really get the best from a programming language, you need to know which features work best in which situations and understand their strengths and weaknesses. It is this understanding that makes the difference between coding and coding well.

Beginning C# 2008 has been written to teach you how to use the C# programming language to solve problems. From the earliest chapters, and from the first introductory concepts, you'll be looking at real-world programming challenges and learning how C# can be used to overcome them. As you progress through the book, the problems become more involved and interesting, while the solutions become correspondingly more complex and powerful as C# features interact to achieve the results that you want.

By the time you've finished reading this book and worked through the sample exercises, you'll be a confident and very competent C# programmer. You will still have many explorations of the .NET Framework API to look forward to in your future career, but you will have a firm foundation to build from and you will know exactly where to go to find the things that you need to progress confidently in your projects.

Christian Gross is dedicated to helping his readers understand every detail of Beginning C# 2008. You can contact him via Skype (christianhgross) if you have bought this book and have a question about something he discusses. If Christian is available when you contact him, he will even try to answer you right away!

Table of contents

  1. About the Author
  2. About the Technical Reviewer
  3. Introduction
  4. 1. Ready, Steady, Go!
    1. Downloading and Installing the Tools
      1. Downloading Visual C# Express
      2. Installing Visual C# Express
    2. Choosing the Application Type
    3. Creating Projects and Solutions
    4. Creating the Windows Application
      1. Viewing the Source Code
      2. Renaming the Solution
      3. Saving the Solution
      4. Running the Windows Application
      5. Making the Windows Application Say Hello
      6. Adding Comments to the Application
    5. Navigating the User Controls of the Solution
    6. Creating the Console Application
      1. Adding a Console Application Project to the Solution
      2. Making the Console Application Say Hello
      3. Setting the Startup Project
      4. Running the Console Project
    7. Creating the Class Library
      1. Adding a Class Library Project to the Solution
      2. Moving Functionality
      3. Defining References
      4. Calling Class Library Functionality
      5. Using Variables and Constants
    8. Understanding How the .NET Framework Works
    9. The Important Stuff to Remember
    10. Some Things for You to Do
  5. 2. Learning About .NET Number and Value Types
    1. Focusing and Organizing Your Development
      1. Organizing the Calculator
      2. Focusing the Calculator
    2. Implementing the Class Library
      1. Writing the Add() Method
      2. Writing Code to Test the Add() Method
      3. Understanding Problems with Numeric Numbers
    3. Understanding Numeric and Value Data Types
      1. Understanding Value and Reference Types
      2. Understanding the CLR Numeric Types
    4. Finishing the Calculator
    5. The Important Stuff to Remember
    6. Some Things for You to Do
  6. 3. Learning About String Manipulations
    1. Organizing the Translation Application
    2. Building the Translator Application
      1. Creating the Translator Class
      2. Translating Hello
      3. Creating the Test Application
      4. Answering the Question of Responsibility
      5. Investigating the String Type
      6. Solving the Extra Whitespace Problem
      7. Quoting Strings
      8. Character Mapping
    3. Dealing with Languages and Cultures
      1. Setting Culture and Language in Windows
      2. Parsing and Processing Numbers
      3. Working with Cultures
    4. The Important Stuff to Remember
    5. Some Things for You to Do
  7. 4. Learning About Data Structures, Decisions, and Loops
    1. Understanding the Depth-First Search Algorithm
    2. Implementing User-Defined Types
      1. Declaring Structs and Classes
      2. Value Type Constraints
    3. Organizing the Search Algorithm
    4. Writing the Depth-First Search Code
      1. Defining and Implementing the Data Structure
      2. Defining the Algorithm Test
      3. Implementing the Depth-First Search Algorithm
      4. Running the Depth-First Search Algorithm
    5. The Important Stuff to Remember
    6. Some Things for You to Do
  8. 5. Learning About C# Exception Handling
    1. Understanding Errors, Exceptions, and Exception Handling
    2. Running the Debugger
    3. Handling Exceptions
      1. Catching Exceptions
      2. Implementing Exception Handlers
      3. Safeguarding Against Stack Unwinding
      4. Filtering Exceptions
    4. Writing Exception-Safe Code
      1. Writing Defensive Code
      2. Using Default State
      3. Processing Errors That Are Warnings
    5. The Important Stuff to Remember
    6. Some Things for You to Do
  9. 6. Learning the Basics of Object-Oriented Programming
    1. Understanding Currency Spreads
    2. Organizing the Currency Exchange Application
    3. Writing Tests for the Currency Exchange Application
      1. Getting Started with Structural Code
      2. Understanding Base Classes
      3. Understanding Inheritance
      4. Using C# Properties
      5. Understanding Inheritance and Scope Modifiers
      6. Handling Verification
      7. Finishing the Base Class
    4. Writing the Active Trader and Hotel Trader Currency Converters
      1. Implementing ActiveCurrencyTrader
      2. Implementing HotelCurrencyTrader
    5. Learning More About Preprocessor Directives,Properties, and Abstract Methods
      1. More Preprocessor Directive Details
      2. More Property Scope Details
      3. More abstract Keyword Details
    6. The Important Stuff to Remember
    7. Some Things for You to Do
  10. 7. Learning About Components and Object Hierarchies
    1. Understanding Some Basic Tax Concepts
    2. Organizing the Tax Application
    3. Programming Using Ideas
      1. Representing Ideas Using C# Interfaces
      2. Understanding How Inheritance and Components Work
    4. Implementing a Tax Engine
      1. Defining the Interfaces
      2. Implementing a Base Class Tax Engine
      3. Using Default Implementations
      4. Implementing a Base Tax Account
    5. Using the Base Functionality of the Tax Engine to Calculate Taxes
      1. Implementing a Tax Engine and Tax Account
      2. Using the Tax Engine
    6. Learning More About Inheritance and Type Casting
      1. More Inheritance Details
      2. More Type-Casting Details
    7. The Important Stuff to Remember
    8. Some Things for You to Do
  11. 8. Learning About Component-Oriented Architecture
    1. Understanding Kernels
    2. Organizing The Lighting Application
    3. Building the Kernel
      1. Defining the Interfaces
      2. Implementing the Kernel
      3. Defining the Kernel As an Interface Instead of a Class
    4. Building a Complete Application
      1. Defining Some Rooms
      2. Instantiating PublicRoom and PrivateRoom
    5. Learning More About Private Classes and Object Initialization
      1. Private Classes
      2. Object Initialization with Nested Data Types
    6. The Important Stuff to Remember
    7. Some Things for You to Do
  12. 9. Learning About Lists, Delegates, and Lambda Expressions
    1. Managing Collections
      1. Managing a Collection Before C# 2.0
      2. Managing a Collection After C# 2.0
    2. The Case of the Code That Feels Wrong
      1. Using Delegates
      2. Using Anonymous Delegates
      3. Multicasting with Delegates
      4. Using Lambda Expressions
    3. Understanding Lambda Expressions
      1. Creating the Algorithm
      2. Implementing the Algorithm Using Lambda Expressions
    4. Learning More About Collection Types
      1. Using a Plain-Vanilla List
      2. Using a Key/Value Pair List
      3. Using a Stack
      4. Using a Queue
    5. The Important Stuff to Remember
    6. Some Things for You to Do
  13. 10. Learning About Persistence
    1. Organizing the Lottery-Prediction System
    2. Piping Data Using a Console
      1. Reading from a File
      2. Building a Shell
      3. Implementing the TextProcessor Application
    3. Piping Binary Data
      1. Defining the Interfaces and Implementing the Shell
      2. Defining the Type
      3. Converting a Text Stream into a Binary Stream
      4. Converting a Binary Stream into a Text Stream
    4. Tweaking Serialization
      1. Performing Custom Serialization
      2. Declaring a Data Member as Nonserializable
      3. Separating Data Objects from Action Objects
    5. Completing Custom Types
      1. Implementing GetHashCode()
      2. Implementing Equals()
    6. The Important Stuff to Remember
    7. Some Things for You to Do
  14. 11. Learning About .NET Generics
    1. Why Use .NET Generics?
    2. The Theory of a Server-Side Spreadsheet
    3. Architecting a Server-Side Spreadsheet
      1. Designing the Architecture
      2. Defining the Server Spreadsheet Interfaces
    4. Implementing the Server Spreadsheet
      1. Using Lambda Expressions in the Spreadsheet
      2. Assigning State Without Knowing the Type
      3. Overriding the ToString() Functionality
      4. Iterating Data Using Enumerators
    5. Using the Spreadsheet
      1. Calculating an Average
      2. Understanding Why the Calculation Worked
    6. The Important Stuff to Remember
    7. Some Things for You to Do
  15. 12. Learning About Application Configuration and Dynamic Loading
    1. Convention over Configuration
      1. Decoupling Using a Configuration Architecture
      2. Decoupling Using a Convention Architecture
    2. Setting Up the Dynamic Loading Projects
      1. Signing an Assembly
      2. Setting the Output Path
    3. Defining and Processing a Configuration File
      1. Creating an XML-Based Configuration File
      2. Adding the Dynamic Loading Configuration Items
      3. Reading a Configuration File
    4. Dynamically Loading an Assembly
      1. Dynamically Instantiating a Type
      2. Enhancing the Configuration File
    5. Loading a Strongly Named Assembly
      1. Relocating a Strongly Named Assembly to the GAC
      2. Using Version Numbers
    6. Implementing a Convention-Based Architecture
    7. Dynamically Loading Base Class or Interface Types
    8. The Important Stuff to Remember
    9. Some Things for You to Do
  16. 13. Learning About Multithreading
    1. Understanding Multitasking
      1. Preemptive Multitasking
      2. Time Slicing
    2. Using Threads
      1. Creating a New Thread
      2. Waiting for the Thread to End
      3. Creating a Thread with State
      4. Synchronizing Between Threads
      5. How Not to Deadlock Your Code (Mostly)
    3. Implementing a Reader/Writer Threaded Architecture
    4. Implementing a Producer/Consumer Architecture
      1. Using a Hidden Producer/Consumer Implementation
      2. Implementing a Generic Producer/Consumer Architecture
      3. Using an Asynchronous Approach
    5. The Important Stuff to Remember
    6. Some Things for You to Do
  17. 14. Learning About Relational Database Data
    1. Understanding Relational Databases
      1. Relational Database Tables
      2. Database Relations
    2. Accessing Relational Databases
    3. Designing a Database Using Visual C# Express
      1. Configuring the Data Source
      2. Adding the Tables
    4. Accessing the Database Using ADO.NET
      1. Connecting to a Database
      2. Adding Table Data
      3. Selecting Data from a Table
      4. Deleting Data from the Database
      5. Closing a Database Connection
      6. Recapping ADO.NET Usage
    5. Using the Dataset Designer
      1. Building Relation Between Tables
      2. Using the Generated Code
    6. The Important Stuff to Remember
    7. Some Things for You to Do
  18. 15. Learning About LINQ
    1. Finding the Frequency of Winning Numbers
      1. Extending the Lottery-Prediction System
      2. Implementing a Frequency Solution
    2. Learning More LINQ Tricks
      1. Selecting and Altering Data
      2. Selecting with Anonymous Types
      3. Processing Multiple Streams
      4. Sorting the Results
      5. Splitting Results into Groups
      6. Performing Set Operations
    3. Using LINQ in Other Contexts
    4. The Important Stuff to Remember
    5. Some Things for You to Do
  19. 16. Writing Functional Code in C#
    1. Why Functional Programming?
    2. The Essence of Functional Programming
      1. Higher-Order Functions
      2. Pure Functions
      3. Function Evaluation
    3. The Important Stuff to Remember
    4. Some Things for You to Do
  20. 17. Learning About Other C# Techniques
    1. Operators
      1. Using Arithmetic Operators
      2. Overloading the Operators
    2. The goto Statement
    3. .NET Generics Constraints
      1. Using the type Constraint
      2. Using the new Constraint
      3. Using the class Constraint
    4. Nullable Types
    5. Partial Classes and Methods
    6. The Important Stuff to Remember
    7. Some Things for You to Do

Product information

  • Title: Beginning C# 2008: From Novice to Professional
  • Author(s):
  • Release date: November 2007
  • Publisher(s): Apress
  • ISBN: 9781590598696