Programming C#

Book description

C# is designed from the ground up for development on Microsoft's new .NET framework. As such, it's a high-performance language that's simple, safe, object-oriented, and Internet-centric. Programming C# teaches this new language in a way that experienced programmers will appreciate--by grounding its applications firmly in the context of Microsoft's .NET platform and the development of desktop and Internet applications. The first part of this book introduces C# fundamentals, then goes on to explain:

  • Classes and objects

  • Inheritance and polymorphism

  • Operator overloading

  • Structs and interfaces

  • Arrays, indexers, and collections

  • String objects and regular expressions

  • Exceptions and bug handling

  • Delegates and events

Part two of Programming C# focuses on development of desktop and Internet applications, including Windows Forms, ADO.NET and ASP.NET. ASP.NET includes Web Forms, for rapid development of web applications, and Web Services for creating objects without user interfaces, to provide services over the Internet. Part three gets to the heart of the .NET Framework, focusing on attributes and reflection, remoting, threads and synchronization, and streams. Part three also illustrates how to interoperate with COM objects. In much the way that you can see the features and personality of the parents and grandparents in young children, you can easily see the influence of Java, C++, Visual Basic, and other languages in C#. The level of information in Programming C# allows you to become productive quickly with C# and to rely on it as a powerful addition to your family of mastered programming languages.

Table of contents

  1. Programming C#
    1. Preface
      1. About This Book
      2. How the Book Is Organized
        1. Part I
        2. Part II
        3. Part III
      3. Who This Book Is For
      4. C# Versus Visual Basic .NET
      5. C# Versus Java
      6. C# versus C++
      7. Conventions Used in This Book
      8. Support
      9. We’d Like to Hear from You
      10. Acknowledgements
    2. I. The C# Language
      1. 1. C# and the .NET Framework
        1. The .NET Platform
        2. The .NET Framework
        3. Compilation and the MSIL
        4. The C# Language
      2. 2. Getting Started:"Hello World”
        1. Classes, Objects, and Types
          1. Methods
          2. Comments
          3. Console Applications
          4. Namespaces
          5. The Dot Operator (.)
          6. The using Keyword
          7. Case Sensitivity
          8. The static Keyword
        2. Developing “Hello World”
          1. Editing “Hello World”
          2. Compiling and Running “Hello World”
        3. Using the Visual Studio .NET Debugger
      3. 3. C# Language Fundamentals
        1. Types
          1. Working with Built-in Types
            1. Choosing a built-in type
            2. Converting built-in types
        2. Variables and Constants
          1. Definite Assignment
          2. Constants
          3. Enumerations
          4. Strings
          5. Identifiers
        3. Expressions
        4. Whitespace
        5. Statements
          1. Unconditional Branching Statements
          2. Conditional Branching Statements
            1. If...else statements
            2. Nested if statements
            3. Switch statements: an alternative to nested ifs
            4. Switch on string statements
          3. Iteration Statements
            1. The goto statement
            2. The while loop
            3. The do . . . while loop
            4. The for loop
            5. The foreach statement
            6. The continue and break statements
        6. Operators
          1. The Assignment Operator (=)
          2. Mathematical Operators
            1. Simple arithmetical operators (+, -, *, /)
            2. The modulus operator (%) to return remainders
          3. Increment and Decrement Operators
            1. Calculate and reassign operators
            2. The prefix and postfix operators
          4. Relational Operators
          5. Use of Logical Operators with Conditionals
          6. Operator Precedence
          7. The Ternary Operator
        7. Namespaces
        8. Preprocessor Directives
          1. Defining Identifiers
          2. Undefining Identifiers
          3. #if, #elif, #else, and #endif
          4. #region
      4. 4. Classes and Objects
        1. Defining Classes
          1. Access Modifiers
          2. Method Arguments
        2. Creating Objects
          1. Constructors
          2. Initializers
          3. Copy Constructors
          4. The this Keyword
        3. Using Static Members
          1. Invoking Static Methods
          2. Using Static Constructors
          3. Using Private Constructors
          4. Using Static Fields
        4. Destroying Objects
          1. The C# Destructor
          2. Finalize Versus Dispose
          3. Implementing the Close Method
          4. The using Statement
        5. Passing Parameters
          1. Passing by Reference
          2. Passing Out Parameters with Definite Assignment
        6. Overloading Methods and Constructors
        7. Encapsulating Data with Properties
          1. The get Accessor
          2. The set Accessor
        8. Readonly Fields
      5. 5. Inheritance and Polymorphism
        1. Specialization and Generalization
        2. Inheritance
          1. Implementing Inheritance
          2. Calling Base Class Constructors
          3. Calling Base Class Methods
          4. Controlling Access
        3. Polymorphism
          1. Creating Polymorphic Types
          2. Creating Polymorphic Methods
          3. Versioning with the new and override Keywords
        4. Abstract Classes
          1. Limitations of Abstract
          2. Sealed Class
        5. The Root of all Classes: Object
        6. Boxing and Unboxing Types
          1. Boxing Is Implicit
          2. Unboxing Must Be Explicit
        7. Nesting Classes
      6. 6. Operator Overloading
        1. Using the operator Keyword
        2. Supporting Other .NET Languages
        3. Creating Useful Operators
        4. Logical Pairs
        5. The Equals Operator
        6. Conversion Operators
      7. 7. Structs
        1. Defining Structs
        2. Creating Structs
          1. Structs as Value Types
          2. Calling the Default Constructor
          3. Creating Structs Without new
      8. 8. Interfaces
        1. Implementing an Interface
          1. Implementing More Than One Interface
          2. Extending Interfaces
          3. Combining Interfaces
        2. Accessing Interface Methods
          1. Casting to an Interface
          2. The is Operator
          3. The as Operator
          4. The is Operator Versus the as Operator
          5. Interface Versus Abstract Class
        3. Overriding Interface Implementations
        4. Explicit Interface Implementation
          1. Selectively Exposing Interface Methods
          2. Member Hiding
          3. Accessing Sealed Classes and Value Types
      9. 9. Arrays, Indexers, and Collections
        1. Arrays
          1. Declaring Arrays
          2. Understanding Default Values
          3. Accessing Array Elements
        2. The foreach Statement
          1. Initializing Array Elements
          2. The params Keyword
          3. Multidimensional Arrays
            1. Rectangular arrays
            2. Jagged arrays
          4. Array Conversions
          5. System.Array
        3. Indexers
          1. Indexers and Assignment
          2. Indexing on Other Values
        4. Collection Interfaces
          1. The IEnumerable Interface
          2. The ICollection Interface
          3. The IComparer Interface
        5. Array Lists
          1. Implementing IComparable
          2. Implementing IComparer
        6. Queues
        7. Stacks
        8. Dictionaries
          1. Hashtables
          2. IDictionary
          3. The Keys and Values Collections
          4. IDictionaryEnumerator Interface
      10. 10. Strings and Regular Expressions
        1. Strings
          1. Creating Strings
          2. The ToString Method
          3. Manipulating Strings
          4. Finding Substrings
          5. Splitting Strings
          6. Manipulating Dynamic Strings
        2. Regular Expressions
          1. Using Regular Expressions: Regex
          2. Using Regex Match Collections
          3. Using Regex Groups
          4. Using CaptureCollection
      11. 11. Handling Exceptions
        1. Throwing and Catching Exceptions
          1. The throw Statement
          2. The catch Statement
            1. Taking corrective action
            2. Unwinding the call stack
            3. Creating dedicated catch statements
          3. The finally Statement
        2. Exception Objects
        3. Custom Exceptions
        4. Rethrowing Exceptions
      12. 12. Delegates and Events
        1. Delegates
          1. Using Delegates to Specify Methods at Runtime
          2. Static Delegates
          3. Delegates as Properties
          4. Setting Order of Execution with Arrays of Delegates
          5. Multicasting
        2. Events
          1. Publishing and Subscribing
          2. Events and Delegates
          3. Decoupling Publishers from Subscribers
    3. II. Programming with C#
      1. 13. Building Windows Applications
        1. Creating a Simple Windows Form
          1. Using Notepad
          2. Using the Visual Studio.Net Designer
        2. Creating a Windows Form 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. Clicking the target TreeView
            3. Handling the Clear button event
          4. Implementing the Copy Button Event
            1. Getting the selected files
            2. Sorting the list of selected files
          5. Handling the Delete Button Event
        3. XML Documentation Comments
        4. Deploying an Application
          1. Deployment Projects
          2. Setup Project
          3. Deployment Locations
            1. Creating a shortcut
            2. Entries in My Documents
            3. Shortcuts in the Start menu
          4. Adding Special Folders
          5. Other View Windows
            1. Making changes to the Registry
            2. Registering file types
            3. Managing the UI during Setup
            4. Other View choices
          6. Building the Setup Project
      2. 14. Accessing Data with ADO.NET
        1. Relational Databases and SQL
          1. Tables, Records, and Columns
          2. Normalization
          3. Declarative Referential Integrity
          4. SQL
        2. The ADO.Net Object Model
          1. DataTables and DataColumns
          2. DataRelations
          3. Rows
          4. Data Adapter
          5. DBCommand and DBConnection
          6. The DataAdapter Object
        3. Getting Started with ADO.NET
        4. Using ADO Managed Providers
        5. Working with Data-Bound Controls
          1. Populating a DataGrid
          2. Customizing the DataSet
          3. Combining Data Tables
        6. Changing Database Records
          1. Accessing the Data
          2. Updating a Record
          3. Deleting a Record
          4. Creating New Records
        7. ADO.NET and XML
      3. 15. ProgrammingWeb Applications with Web Forms
        1. Understanding Web Forms
          1. Web Form Events
            1. Postback versus non-postback events
            2. State
          2. Web Form Life Cycle
        2. Creating a Web Form
        3. Adding Controls
        4. Data Binding
          1. Setting Initial Properties
          2. Connecting to the Database
        5. Responding to Postback Events
        6. ASP.NET and C#
      4. 16. Programming Web Services
        1. SOAP, WSDL, and Discovery
          1. Server-side Support
          2. Client-side Support
        2. Building a Web Service
          1. Testing Your Web Service
          2. Viewing the WSDL Contract
        3. Creating the Proxy
    4. III. C# and the .NET CLR
      1. 17. Assemblies and Versioning
        1. PE Files
        2. Metadata
        3. Security Boundary
        4. Versioning
        5. Manifests
          1. Modules in the Manifest
          2. Module Manifests
          3. Other Required Assemblies
        6. Multi-Module Assemblies
          1. Benefiting from Multi-Module Assemblies
          2. Building a Multi-Module Assembly
            1. Testing the assembly
            2. Loading the assembly
        7. Private Assemblies
        8. Shared Assemblies
          1. The End of DLL Hell
          2. Versions
          3. Strong Names
          4. The Global Assembly Cache
          5. Building a Shared Assembly
            1. Step 1: Create a strong name
            2. Step 2: Put the shared assembly in the GAC
      2. 18. Attributes and Reflection
        1. Attributes
        2. Intrinsic Attributes
          1. Attribute Targets
          2. Applying Attributes
        3. Custom Attributes
          1. Declaring an Attribute
          2. Naming an Attribute
          3. Constructing an Attribute
          4. Using an Attribute
        4. Reflection
          1. Viewing MetaData
          2. Type Discovery
          3. Reflecting on a Type
            1. Finding all type members
            2. Finding type methods
            3. Finding particular type members
          4. Late Binding
        5. Reflection Emit
          1. Dynamic Invocation with InvokeMember( )
          2. Dynamic Invocation with Interfaces
          3. Dynamic Invocation with Reflection Emit
      3. 19. Marshaling and Remoting
        1. Application Domains
          1. Creating and Using App Domains
          2. Marshaling Across App Domain Boundaries
            1. Understanding marshaling with proxies
            2. Specifying the marshaling method
        2. Context
          1. Context-Bound and Context-Agile Objects
          2. Marshaling Across Context Boundaries
        3. Remoting
          1. Understanding Server Object Types
          2. Specifying a Server with an Interface
          3. Building a Server
          4. Building the Client
          5. Using SingleCall
          6. Understanding RegisterWellKnownServiceType
          7. Understanding Endpoints
      4. 20. Threads and Synchronization
        1. Threads
          1. Starting Threads
          2. Joining Threads
          3. Suspending Threads
          4. Killing Threads
        2. Synchronization
          1. Using Interlocked
          2. Using Locks
          3. Using Monitors
        3. Race Conditions and Deadlocks
          1. Race Conditions
          2. Deadlock
      5. 21. Streams
        1. Files and Directories
          1. Working with Directories
          2. Creating a DirectoryInfo Object
          3. Working with Files
          4. Modifying Files
        2. Reading and Writing Data
          1. Binary Files
          2. Buffered Streams
          3. Working with Text Files
        3. Asynchronous I/O
        4. Network I/O
          1. Creating a Network Streaming Server
          2. Creating a Streaming Network Client
          3. Handling Multiple Connections
          4. Aysnchronous Network File Streaming
        5. Web Streams
        6. Serialization
          1. Using a Formatter
          2. Working with Serialization
            1. Serializing the object
            2. Deserializing the object
          3. Handling Transient Data
        7. Isolated Storage
      6. 22. Programming .NET and COM
        1. Importing ActiveX Controls
          1. Creating an ActiveX Control
          2. Importing a Control in .NET
            1. Importing a control
            2. Adding a control to the Visual Studio toolbox
        2. Importing COM Components
          1. Coding the COMTestForm program
          2. Importing the COM .DLL to .NET
          3. Importing the Type Library
          4. Importing Manually
          5. Creating a Test Program
          6. Using Late Binding and Reflection
        3. Exporting .NET Components
          1. Creating a Type Library
        4. P/Invoke
        5. Pointers
    5. A. C# Keywords
    6. Index
    7. Colophon

Product information

  • Title: Programming C#
  • Author(s): Jesse Liberty
  • Release date: July 2001
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596001179