You are previewing Illustrated C# 2010.
O'Reilly logo
Illustrated C# 2010

Book Description

This book presents the C# language in a uniquely succinct and visual format. Often in programming books, the information can be hidden in a vast sea of words. As a programmer who has over the years used a dozen programming languages, the author understands it can sometimes be difficult to slog through another 1,000-page book of dense text to learn a new language. There are likely many other programmers who feel the same way. To address this situation, this book explains C# using figures; short, focused code samples; and clear, concise explanations.

Figures are of prime importance in this book. While teaching programming seminars, Daniel Solis found that he could almost watch the lightbulbs going on over the students' heads as he drew the figures on the whiteboard. In this text, he has distilled each important concept into simple but accurate illustrations. The visual presentation of the content will give you an understanding of C# that's not possible with text alone.

For something as intricate and precise as a programming language, however, there must be text as well as figures. But rather than long, wordy explanations, Solis has used short, concise descriptions and bulleted lists to make each important piece of information visually distinct.

By the end of this book, you'll have a thorough working knowledge of all aspects of the C# language, whether you're a novice programmer or a seasoned veteran of other languages. If you want a long, leisurely, verbose explanation of the language, this is not the book for you. But if you want a concise, thorough, visual presentation of C#, this is just what you're looking for.

What you'll learn

  • Details of the C# 2010 language presented in a clear, concise treatment

  • New features in the latest version of .NET, in the author's unique visual style

  • How C# differs from and is similar to other programming languages, aiding migrating C++ and VB programmers who already know how languages work

Who this book is for

  • Visual Basic programmers interested in moving to C#

  • C++ programmers interested in moving to C#

  • Novice programmers interested in learning C#

  • Students in introductory programming classes learning C#

Table of Contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Author
  6. Acknowledgments
  7. Introduction
  8. CHAPTER 1: C# and the .NET Framework
    1. Before .NET
    2. Enter Microsoft .NET
    3. Compiling to the Common Intermediate Language
    4. Compiling to Native Code and Execution
    5. The Common Language Runtime
    6. The Common Language Infrastructure
    7. Review of the Acronyms
  9. CHAPTER 2: Overview of C# Programming
    1. A Simple C# Program
    2. More About SimpleProgram
    3. Identifiers and Keywords
    4. Naming Conventions
    5. Keywords
    6. Main: The Starting Point of a Program
    7. Whitespace
    8. Statements
    9. Simple Statements
    10. Blocks
    11. Text Output from a Program
    12. Write
    13. WriteLine
    14. The Format String
    15. Multiple Markers and Values
    16. Comments: Annotating the Code
    17. More About Comments
    18. Documentation Comments
    19. Summary of Comment Types
  10. CHAPTER 3: Types, Storage, and Variables
    1. A C# Program Is a Set of Type Declarations
    2. A Type Is a Template
    3. Instantiating a Type
    4. Data Members and Function Members
    5. Predefined Types
    6. User-Defined Types
    7. The Stack and the Heap
    8. Value Types and Reference Types
    9. Variables
    10. Static Typing and the dynamic Keyword
    11. Nullable Types
  11. CHAPTER 4: Classes: The Basics
    1. Overview of Classes
    2. Programs and Classes: A Quick Example
    3. Declaring a Class
    4. Class Members
    5. Creating Variables and Instances of a Class
    6. Allocating Memory for the Data
    7. Instance Members
    8. Access Modifiers
    9. Accessing Members from Inside the Class
    10. Accessing Members from Outside the Class
    11. Putting It All Together
  12. CHAPTER 5: Methods
    1. The Structure of a Method
    2. Local Variables
    3. Local Constants
    4. Method Invocations
    5. Return Values
    6. Parameters
    7. Value Parameters
    8. Reference Parameters
    9. Output Parameters
    10. Parameter Arrays
    11. Summary of Parameter Types
    12. Method Overloading
    13. Named Parameters
    14. Optional Parameters
    15. Stack Frames
    16. Recursion
  13. CHAPTER 6: More About Classes
    1. Class Members
    2. Instance Class Members
    3. Static Fields
    4. Accessing Static Members from Outside the Class
    5. Static Function Members
    6. Other Static Class Member Types
    7. Member Constants
    8. Properties
    9. Instance Constructors
    10. Static Constructors
    11. Object Initializers
    12. Destructors
    13. Comparing Constructors and Destructors
    14. The readonly Modifier
    15. The this Keyword
    16. Indexers
    17. Access Modifiers on Accessors
    18. Partial Classes and Partial Types
  14. CHAPTER 7: Classes and Inheritance
    1. Class Inheritance
    2. Accessing the Inherited Members
    3. Hiding Members of a Base Class
    4. Base Access
    5. Using References to a Base Class
    6. Constructor Execution
    7. Inheritance Between Assemblies
    8. Member Access Modifiers
    9. Abstract Members
    10. Abstract Classes
    11. Sealed Classes
    12. Static Classes
    13. Extension Methods
  15. CHAPTER 8: Expressions and Operators
    1. Expressions
    2. Literals
    3. Integer Literals
    4. Character Literals
    5. String Literals
    6. Order of Evaluation
    7. Simple Arithmetic Operators
    8. The Remainder Operator
    9. Relational and Equality Comparison Operators
    10. Increment and Decrement Operators
    11. Conditional Logical Operators
    12. Logical Operators
    13. Shift Operators
    14. Assignment Operators
    15. The Conditional Operator
    16. Unary Arithmetic Operators
    17. User-Defined Type Conversions
    18. Operator Overloading
    19. The typeof Operator
    20. Other Operators
  16. CHAPTER 9: Statements
    1. What Are Statements?
    2. Expression Statements
    3. Flow-of-Control Statements
    4. The if Statement
    5. The if . . . else Statement
    6. The switch Statement
    7. The while Loop
    8. The do Loop
    9. The for Loop
    10. Jump Statements
    11. The break Statement
    12. The continue Statement
    13. Labeled Statements
    14. The goto Statement
    15. The using Statement
    16. Other Statements
  17. CHAPTER 10: Namespaces and Assemblies
    1. Referencing Other Assemblies
    2. Namespaces
    3. The using Directives
    4. The Structure of an Assembly
    5. The Identity of an Assembly
    6. Strongly Named Assemblies
    7. Private Deployment of an Assembly
    8. Shared Assemblies and the GAC
    9. Configuration Files
    10. Delayed Signing
  18. CHAPTER 11: Exceptions
    1. What Are Exceptions?
    2. The try Statement
    3. The Exception Classes
    4. The catch Clause
    5. Examples Using Specific catch Clauses
    6. The catch Clauses Section
    7. The finally Block
    8. Finding a Handler for an Exception
    9. Searching Further
    10. Throwing Exceptions
    11. Throwing Without an Exception Object
  19. CHAPTER 12: Structs
    1. What Are Structs?
    2. Structs Are Value Types
    3. Assigning to a Struct
    4. Constructors and Destructors
    5. Field Initializers Are Not Allowed
    6. Structs Are Sealed
    7. Boxing and Unboxing
    8. Structs As Return Values and Parameters
    9. Additional Information About Structs
  20. CHAPTER 13: Enumerations
    1. Enumerations
    2. Bit Flags
    3. More About Enums
  21. CHAPTER 14: Arrays
    1. Arrays
    2. Types of Arrays
    3. An Array As an Object
    4. One-Dimensional and Rectangular Arrays
    5. Instantiating a One-Dimensional or Rectangular Array
    6. Accessing Array Elements
    7. Initializing an Array
    8. Jagged Arrays
    9. Comparing Rectangular and Jagged Arrays
    10. The foreach Statement
    11. Array Covariance
    12. Useful Inherited Array Members
    13. Comparing Array Types
  22. CHAPTER 15: Delegates
    1. What Is a Delegate?
    2. Declaring the Delegate Type
    3. Creating the Delegate Object
    4. Assigning Delegates
    5. Combining Delegates
    6. Adding Methods to Delegates
    7. Removing Methods from a Delegate
    8. Invoking a Delegate
    9. Delegate Example
    10. Invoking Delegates with Return Values
    11. Invoking Delegates with Reference Parameters
    12. Anonymous Methods
    13. Lambda Expressions
  23. CHAPTER 16: Events
    1. Events Are Like Delegates
    2. Overview of Source Code Components
    3. Declaring an Event
    4. Raising an Event
    5. Subscribing to an Event
    6. Standard Event Usage
    7. The MyTimerClass Code
    8. Event Accessors
  24. CHAPTER 17: Interfaces
    1. What Is an Interface?
    2. Declaring an Interface
    3. Implementing an Interface
    4. An Interface Is a Reference Type
    5. Using the as Operator with Interfaces
    6. Implementing Multiple Interfaces
    7. Implementing Interfaces with Duplicate Members
    8. References to Multiple Interfaces
    9. An Inherited Member As an Implementation
    10. Explicit Interface Member Implementations
    11. Interfaces Can Inherit Interfaces
  25. CHAPTER 18: Conversions
    1. What Are Conversions?
    2. Implicit Conversions
    3. Explicit Conversions and Casting
    4. Types of Conversions
    5. Numeric Conversions
    6. Reference Conversions
    7. Boxing Conversions
    8. Unboxing Conversions
    9. User-Defined Conversions
    10. The is Operator
    11. The as Operator
  26. CHAPTER 19: Generics
    1. What Are Generics?
    2. Generics in C#
    3. Generic Classes
    4. Declaring a Generic Class
    5. Creating a Constructed Type
    6. Creating Variables and Instances
    7. Constraints on Type Parameters
    8. Generic Methods
    9. Extension Methods with Generic Classes
    10. Generic Structs
    11. Generic Delegates
    12. Generic Interfaces
    13. Covariance and Contravariance in Generics
  27. CHAPTER 20: Enumerators and Iterators
    1. Enumerators and Enumerable Types
    2. Using the IEnumerator Interface
    3. The IEnumerable Interface
    4. The Noninterface Enumerator
    5. The Generic Enumeration Interfaces
    6. The IEnumerator<T> Interface
    7. The IEnumerable<T> Interface
    8. Iterators
    9. Common Iterator Patterns
    10. Producing Enumerables and Enumerators
    11. Producing Multiple Enumerables
    12. Producing Multiple Enumerators
    13. Behind the Scenes with Iterators
  28. CHAPTER 21: Introduction to LINQ
    1. What Is LINQ?
    2. LINQ Providers
    3. Query Syntax and Method Syntax
    4. Query Variables
    5. The Structure of Query Expressions
    6. The Standard Query Operators
    7. LINQ to XML
  29. CHAPTER 22: Introduction to Asynchronous Programming
    1. Processes, Threads, and Asynchronous Programming
    2. Parallel Loops
    3. The BackgroundWorker Class
    4. Asynchronous Programming Patterns
    5. BeginInvoke and EndInvoke
    6. Timers
  30. CHAPTER 23: Preprocessor Directives
    1. What Are Preprocessor Directives?
    2. General Rules
    3. The #define and #undef Directives
    4. Conditional Compilation
    5. The Conditional Compilation Constructs
    6. Diagnostic Directives
    7. Line Number Directives
    8. Region Directives
    9. The #pragma warning Directive
  31. CHAPTER 24: Reflection and Attributes
    1. Metadata and Reflection
    2. The Type Class
    3. Getting a Type Object
    4. What Is an Attribute?
    5. Applying an Attribute
    6. Predefined, Reserved Attributes
    7. More About Applying Attributes
    8. Custom Attributes
    9. Accessing an Attribute
  32. CHAPTER 25: Other Topics
    1. Overview
    2. Strings
    3. Parsing Strings to Data Values
    4. More About the Nullable Types
    5. Method Main
    6. Documentation Comments
    7. Nested Types
    8. Interoperating with COM
  33. Index