Cover image for C# Essentials, 2nd Edition

Book description

Concise but thorough, this second edition of C# Essentials introduces the Microsoft C# programming language, including the Microsoft .NET Common Language Runtime (CLR) and .NET Framework Class Libraries (FCL) that support it. This book?s compact format and terse presentation of key concepts serve as a roadmap to the online documentation included with the Microsoft .NET Framework SDK; the many examples provide much-needed context. This new edition has been updated to cover the final release of the C# language. In addition to overviews of C#, the CLR, and the FCL, this new edition of C# Essentials covers:

  • Every C# language element and its syntax, in reference format, including new keywords

  • The major C# datatypes, with code examples

  • Common C# programming tasks

  • Interoperation with legacy Win32 APIs and COM components, and the use of C/C++ style pointers within the managed context of the CLR

  • Common development issues

C# Essentials is an easy way for experienced programmers to evaluate and get up to speed quickly on the language best suited to developing web applications and services on the new Microsoft .NET platform.

Table of Contents

  1. C# Essentials, 2nd Edition
  2. Preface
    1. Audience
    2. About This Book
    3. C# Online
    4. Conventions Used in This Book
    5. How to Contact Us
    6. Acknowledgments
      1. Ben Albahari
      2. Peter Drayton
      3. Brad Merrill
  3. 1. Introduction
    1. C# Language
    2. Common Language Runtime
    3. Framework Class Library
    4. A First C# Program
  4. 2. C# Language Reference
    1. Identifiers
    2. Types
      1. Type Instances
      2. Example: Building and Using Types
      3. Implicit and Explicit Conversions
      4. Categories of Types
        1. Value types
        2. Reference types
        3. Pointer types
      5. Predefined Types
        1. Integral types
          1. Integral conversions
        2. Floating-point types
          1. Floating-point conversions
        3. decimal type
          1. decimal conversions
        4. char type
          1. char conversions
        5. bool type
          1. bool conversions
        6. object type
        7. string type
      6. Types and Memory
        1. Memory for value types
        2. Memory for reference types
        3. Value types and reference types side by side
      7. Unified Type System
        1. Simple types are value types
        2. Value types expand the set of simple types
        3. Boxing and unboxing value types
    3. Variables
      1. Definite Assignment
      2. Default Values
    4. Expressions and Operators
      1. Operator Precedence
      2. Arithmetic Overflow Check Operators
    5. Statements
      1. Expression Statements
      2. Declaration Statements
      3. Empty Statements
      4. Selection Statements
        1. if-else statement
        2. switch statement
      5. Loop Statements
        1. while loops
        2. do-while loops
        3. for loops
        4. foreach loops
      6. jump Statements
        1. break statement
        2. continue statement
        3. goto statement
        4. return statement
        5. throw statement
        6. lock statement
        7. using statement
    6. Organizing Types
      1. Files
      2. Namespaces
        1. Nesting namespaces
        2. Using a type with its fully qualified name
        3. using keyword
        4. Aliasing types and namespaces
        5. Global namespace
    7. Inheritance
      1. Class Conversions
        1. as operator
        2. is operator
      2. Polymorphism
      3. Virtual Function Members
      4. Abstract Classes and Members
      5. Sealed Methods and Sealed Classes
      6. Hiding Inherited Members
      7. Versioning Virtual Function Members
    8. Access Modifiers
      1. Restrictions on Access Modifiers
    9. Classes and Structs
      1. Differences Between Classes and Structs
      2. Instance and Static Members
      3. Fields
      4. Constants
        1. Versioning with constants
      5. Properties
      6. Indexers
      7. Methods
        1. Signatures
        2. Passing arguments by value
        3. ref modifier
        4. out modifier
        5. params modifier
        6. Overloading methods
      8. Operators
        1. Implementing value equality
        2. Logically paired operators
        3. Custom implicit and explicit conversions
        4. Three-state logic operators
        5. Indirectly overloadable operators
      9. Instance Constructors
        1. Calling base class constructors
        2. Field initialization order
        3. Constructor access modifiers
      10. Static Constructors
        1. Base class constructor order
        2. Static field initialization order
        3. Nondeterminism of static constructor calls
      11. Self-Referencing
        1. this keyword
        2. base keyword
      12. Destructors and Finalizers
      13. Nested Types
    10. Interfaces
      1. Defining an Interface
      2. Implementing an Interface
      3. Using an Interface
      4. Extending an Interface
      5. Explicit Interface Implementation
      6. Reimplementing an Interface
      7. Interface Conversions
    11. Arrays
      1. Multidimensional Arrays
      2. Local and Field Array Declarations
      3. Array Length and Rank
      4. Bounds Checking
      5. Array Conversions
    12. Enums
      1. Enum Operators
      2. Enum Conversions
    13. Delegates
      1. Multicast Delegates
      2. Delegates Compared with Function Pointers
      3. Delegates Compared with Interfaces
    14. Events
      1. Defining a Delegate for an Event
      2. Storing Data for an Event with EventArgs
      3. Declaring and Firing an Event
      4. Acting on an Event with Event Handlers
      5. Event Accessors
    15. try Statements and Exceptions
      1. try Statement
      2. Exceptions
      3. catch
        1. Omitting the exception variable
        2. Omitting the catch expression
        3. Specifying multiple catch clauses
      4. finally
      5. Key Properties of the System.Exception Class
    16. Attributes
      1. Attribute Classes
      2. Named and Positional Parameters
      3. Explicitly Specifying Attribute Targets
      4. Specifying Multiple Attributes
    17. Unsafe Code and Pointers
      1. Pointer Types
      2. Unsafe Code
      3. The fixed Statement
      4. Pointer to Member Operator
      5. The stackalloc Keyword
      6. void*
      7. Pointers to Unmanaged Code
    18. Preprocessor Directives
      1. Preprocessor Directives
    19. XML Documentation
      1. C/C++-Style Comments
      2. Documentation Comments
      3. XML Documentation Files
      4. Predefined XML Tags
      5. User-Defined Tags
      6. Type or Member Cross-References
  5. 3. Programming the.NET Framework
    1. Common Types
      1. Object Class
        1. Creating FCL-friendly types
      2. ICloneable Interface
      3. IComparable Interface
      4. IFormattable Interface
    2. Math
      1. Language Support for Math
      2. Special Types and Operators
      3. Math Class
      4. Random Class
    3. Strings
      1. String Class
      2. Immutability of Strings
      3. String Interning
      4. Formatting Strings
      5. Indexing Strings
      6. Encoding Strings
      7. StringBuilder Class
    4. Collections
      1. Concrete Collection Classes
        1. ArrayList class
        2. BitArray class
        3. Hashtable class
        4. Queue class
        5. SortedList class
        6. Stack class
        7. StringCollection class
      2. Collection Interfaces
        1. IEnumerable interface
        2. IEnumerator interface
        3. ICollection interface
        4. IComparer interface
        5. IList interface
        6. IDictionary interface
        7. IDictionaryEnumerator interface
        8. IHashCodeProvider interface
    5. Regular Expressions
      1. Regex Class
      2. Match and MatchCollection Classes
      3. Group Class
      4. Capture and CaptureCollection Classes
      5. Using Regular Expressions
    6. Input/Output
      1. Streams and Backing Stores
        1. Abstract Stream class
        2. Concrete Stream-derived classes
        3. Encapsulating raw streams
        4. Abstract TextReader/TextWriter classes
        5. StreamReader and StreamWriter classes
        6. StringReader and StringWriter classes
      2. Directories and Files
    7. Networking
      1. Network Programming Models
      2. Generic Request/Response Architecture
      3. HTTP-Specific Support
      4. Adding New Protocol Handlers
      5. Using TCP, UDP, and Sockets
      6. Using DNS
    8. Threading
      1. Thread Synchronization
        1. The lock statement
        2. Pulse and Wait operations
        3. Deadlocks
        4. Atomic operations
      2. Common Thread Types
      3. Monitor Class
        1. Enter and Exit methods
        2. TryEnter methods
        3. Wait methods
        4. Pulse and PulseAll methods
    9. Assemblies
      1. Elements of an Assembly
      2. Packaging
      3. Deployment
      4. Versioning
      5. Type Resolution
      6. Security Permissions
    10. Reflection
      1. Type Hierarchy
        1. Types, members, and nested types
        2. Assemblies and modules
        3. AppDomains
      2. Retrieving the Type for an Instance
      3. Retrieving a Type Directly
      4. Reflecting Over a Type Hierarchy
      5. Late Binding to Types
      6. Activation
      7. Advanced Uses of Reflection
      8. Creating New Types at Runtime
    11. Custom Attributes
      1. Language Support for Custom Attributes
      2. Compiler Support for Custom Attributes
      3. Runtime Support for Custom Attributes
      4. Predefined Attributes
        1. AttributeUsage attribute
        2. Conditional attribute
        3. Obsolete attribute
        4. CLSCompliant attribute
        5. Serializable attribute
        6. NonSerialized attribute
      5. Defining a New Custom Attribute
      6. Retrieving a Custom Attribute at Runtime
    12. Automatic Memory Management
      1. The Garbage Collector
      2. Optimization Techniques
      3. Finalizers
      4. Dispose and Close Methods
    13. Interop with Native DLLs
      1. Marshaling Common Types
      2. Marshaling Classes and Structs
      3. In and Out Marshaling
      4. Callbacks from Unmanaged Code
      5. Predefined Interop Support Attributes
        1. DllImport attribute
        2. StructLayout attribute
        3. FieldOffset attribute
        4. MarshalAs attribute
        5. In attribute
        6. Out attribute
    14. Interop with COM
      1. Binding COM and C# Objects
      2. Exposing COM Objects to C#
      3. Exposing C# Objects to COM
      4. COM Mapping in C#
      5. Common COM Interop Support Attributes
        1. ComVisible attribute
        2. DispId attribute
        3. ProgId attribute
        4. Guid attribute
        5. InterfaceType attribute
        6. ComRegisterFunction attribute
  6. 4. Framework Class Library Overview
    1. Core Types
    2. Text
    3. Collections
    4. Streams and I/O
    5. Networking
    6. Threading
    7. Security
    8. Reflection and Metadata
    9. Assemblies
    10. Serialization
    11. Remoting
    12. Web Services
    13. Data Access
    14. XML
    15. Graphics
    16. Rich Client Applications
    17. Web-Based Applications
    18. Globalization
    19. Configuration
    20. Advanced Component Services
    21. Diagnostics and Debugging
    22. Interoperating with Unmanaged Code
    23. Compiler and Tool Support
    24. Runtime Facilities
    25. Native OS Facilities
    26. Undocumented Types
  7. 5. Essential .NET Tools
  8. A. C# Keywords
  9. B. Regular Expressions
  10. C. Format Specifiers
    1. Picture Format Specifiers
    2. DateTime Format Specifiers
  11. D. Data Marshaling
  12. E. Working with Assemblies
    1. Building Shareable Assemblies
      1. Building Modules
      2. Linking Modules to Assemblies
      3. Building with Your New Assemblies
      4. Sharing Assemblies
    2. Managing the Global Assembly Cache
    3. Using nmake
  13. F. Namespaces and Assemblies
  14. Index
  15. About the Authors
  16. Colophon
  17. Copyright