You are previewing Application Development Using C# and .NET.
O'Reilly logo
Application Development Using C# and .NET

Book Description

Build industrial-strength .NET applications with C#!

  • Practical, useful information on the .NET Framework, the Common Language Runtime, ADO.NET, ASP.NET, Web Services, security, interoperability, and more

  • Running case study: see how concepts work together when you build .NET applications

  • Experienced C++, Java, and Visual Basic programmers: become effective with .NET!

This book gives experienced developers all the practical insight they need to build enterprise applications for Microsoft's .NET platform using C#. Using extensive code examples and a running case study, the authors illuminate the .NET concepts and technologies that offer the greatest power and value. They cover the entire process of constructing a .NET application: creating a monolithic C# console application; enhancing it with a Windows Forms interface; isolating functionality inside components, adding database access and security; and finally, delivering functionality through ASP.NET and Web Services.

  • .NET Framework and Common Language Runtime fundamentals for experienced programmers

  • Key .NET features: interfaces, attributes, collections, threading, remoting, assemblies, and more

  • Hands-on coverage of ADO.NET, ASP.NET, Web Services, and user interface programming

  • Component deployment and versioning

  • Ensuring interoperability with diverse and legacy systems

  • Includes a self-contained C# overview for those new to the language

Part of The Integrated .NET series from Object Innovations.

Table of Contents

  1. Copyright
    1. Dedication
  2. The Integrated .NET Series From Object Innovations
  3. Preface
    1. Organization
    2. Sample Programs
    3. Caveat
    4. Web Sites
  4. Acknowledgments
  5. The Integrated .NET Series from Object Innovations and Prentice Hall PTR
    1. Introduction
    2. Introductory .NET Language Books
    3. Introduction to C# Using .NET
    4. Introduction to Programming Visual Basic Using .NET
    5. Programming Perl in the .NET Environment
    6. Intermediate .NET Framework Books
    7. Application Development Using C# and .NET
    8. Application Development Using Visual Basic .NET
    9. .NET Architecture and Programming Using Visual C++
    10. Fundamentals of Web Applications Using .NET and XML
  6. 1. What Is Microsoft .NET?
    1. Microsoft and the Web
      1. Applications in the Internet Age
      2. Web Services
      3. ASP.NET
      4. Open Standards and Interoperability
      5. Communications Protocols
    2. Windows on the Desktop
      1. Problems with Windows
      2. The Glass House and Thin Clients
      3. A Robust Windows
    3. A New Programming Platform
      1. .NET Framework
      2. Common Language Runtime
        1. Managed Code and Data
        2. Verifiable Code
      3. Multiple Language Development
      4. Development Tools
      5. The Importance of Tools
    4. The Role of XML
      1. Success Factors for Web Services
    5. Summary
  7. 2. .NET Fundamentals
    1. Problems of Windows Development
    2. Applications of the Future
    3. .NET Overview
      1. The Magic of Metadata
      2. .NET Framework Class Library
      3. Interface-Based Programming
      4. Everything Is an Object
      5. Common Type System
      6. ILDASM
      7. Language Interoperability
      8. Managed Code
      9. Assemblies
      10. JIT Compilation
      11. Performance
    4. Summary
  8. 3. C# Overview for Sophisticated Programmers
    1. Hello World in C#
      1. Compiling and Running (Command Line)
      2. Program Structure
      3. Namespaces
    2. Performing Calculations in C#
      1. Variables
      2. Literals
      3. C# Operators and Expressions
      4. Output and Formatting
        1. Placeholders
        2. Format Strings
        3. Sample Formatting Code
      5. Control Structures
        1. Switch Statement
      6. Methods
      7. Console Input in C#
        1. Using the InputWrapper Class
        2. Compiling Multiple Files
        3. InputWrapper Class Implementation
    3. Classes
      1. Classes as Structured Data
        1. Classes and Objects
        2. References
        3. Constructors
        4. Default Constructor
        5. Instantiating and Using an Object
        6. Assigning Object References
        7. Garbage Collection
      2. Methods
        1. Public and Private
        2. This
        3. Sample Program
      3. Properties
      4. Static Fields and Methods
        1. Static Methods
        2. Sample Program
      5. Static Constructor
      6. Constant and Readonly Fields
    4. C# Type System
      1. Overview of Types in C#
        1. Value Types
        2. Reference Types
        3. Pointer Types
      2. Value Types
        1. Simple Types
        2. Types in System Namespace
        3. Structures
        4. Enumeration Types
      3. Reference Types
        1. Class Types
        2. Object
        3. String
      4. Default Values
      5. Boxing and Unboxing
    5. Strings
      1. Characters
        1. ASCII and Unicode
        2. Escape Sequences
      2. String Class
      3. Language Support
        1. String Literals and Initialization
        2. Concatenation
        3. Index
        4. Relational Operators
      4. String Equality
      5. String Comparison
      6. String Input
      7. String Methods and Properties
        1. Length
        2. ToUpper
        3. ToLower
        4. Substring
        5. IndexOf
      8. StringBuilder Class
    6. Arrays and Indexers
      1. Arrays
        1. One-Dimensional Arrays
      2. System.Array
      3. Sample Program
      4. Interfaces for System.Array
      5. Random-Number Generation
        1. Constructors
        2. Next Methods
        3. NextDouble Method
      6. Jagged Arrays
      7. Rectangular Arrays
      8. Arrays as Collections
      9. Indexers
    7. More about Methods
      1. Parameter Passing
      2. Value Parameters
      3. Reference Parameters
      4. Output Parameters
      5. Method Overloading
        1. Modifiers as Part of the Signature
      6. Variable-Length Parameter Lists
      7. Operator Overloading
    8. Exceptions
      1. Exception Fundamentals
        1. .NET Exception Handling
        2. Exception Flow of Control
        3. Context and Stack Unwinding
        4. Example Program
        5. System.Exception
      2. User-Defined Exception Classes
      3. Structured Exception Handling
        1. Finally Block
      4. Inner Exceptions
      5. Multiple Catch Handlers
    9. Unsafe Code
      1. Unsafe Blocks
      2. Pointers
      3. Fixed Memory
    10. Summary
  9. 4. Object-Oriented Programming in C #
    1. Review of Object-Oriented Concepts
      1. Objects
        1. Objects in the Real World
        2. Object Models
        3. Reusable Software Components
        4. Objects in Software
        5. Abstraction
        6. Encapsulation
      2. Classes
        1. Inheritance
        2. Abstract Classes
        3. Relationships Among Classes
      3. Polymorphism
    2. Acme Travel Agency Case Study: Design
      1. Designing the Abstractions
        1. Reservable
        2. Reservation
        3. Broker
        4. ReservationResult
      2. Base Class Logic
        1. Reserve
        2. Lists of Reservations and Reservables
      3. Designing the Encapsulation
    3. Inheritance in C#
      1. Inheritance Fundamentals
        1. C# Inheritance Syntax
        2. Changing the Interface to Existing Members
        3. Invoking Base Class Constructors
    4. Access Control
      1. Class Accessibility
        1. Public
        2. Internal
      2. Member Accessibility
        1. Public
        2. Private
        3. Protected
        4. Internal
        5. Internal Protected
      3. Access Control in the Case Study
    5. Acme Travel Agency Case Study: Implementation
      1. Running the Case Study
      2. HotelReservation
      3. HotelBroker
      4. Customers
      5. Namespace
      6. TestHotel
    6. More about Inheritance
      1. Employee Class Hierarchy
      2. Method Hiding
      3. Static Binding
        1. Type Conversions in Inheritance
      4. Virtual Methods
        1. Virtual Methods and Efficiency
        2. Method Overriding
      5. The Fragile Base Class Problem
      6. Polymorphism
      7. Abstract Classes
      8. Sealed Classes
      9. Heterogeneous Collections
    7. Summary
  10. 5. C# in the .NET Framework
    1. System.Object
      1. Public Instance Methods of object
        1. Equals
        2. ToString
        3. GetHashCode
        4. GetType
      2. Protected Instance Methods
        1. MemberWiseClone
        2. Finalize
      3. Generic Interfaces and Standard Behavior
      4. Using object Methods in the Customer Class
        1. Default Methods of Object
        2. Overriding Methods of Object
    2. Collections
      1. ArrayList Example
        1. Customers Class
    3. Interfaces
      1. Interface Fundamentals
        1. Interfaces in C#
        2. Implementing an Interface
        3. Using an Interface
      2. Multiple Interfaces
        1. Interface Inheritance
        2. Implementing Multiple Interfaces
        3. Using Multiple Interfaces
      3. Dynamic Use of Interfaces
        1. As Operator
        2. Is Operator
      4. Explicit Interface Implementation
    4. Acme Travel Agency Case Study: Step 2
      1. The Contracts
        1. Customer Contract
        2. Hotel Contracts
      2. The Implementation
        1. Structures
    5. Generic Interfaces in .NET
      1. Collection Interfaces
        1. Interface Documentation
        2. IEnumerable And IEnumerator
        3. ICollection
        4. IList
      2. Copy Semantics and ICloneable
        1. Shallow Copy and Deep Copy
        2. Example Program
        3. Reference Copy by Assignment
        4. Memberwise Clone
        5. Using ICloneable
      3. Comparing Objects
        1. Sorting an Array
        2. Implementing IComparable
      4. Understanding Frameworks
    6. Delegates
      1. Declaring a Delegate
      2. Defining a Method
      3. Creating a Delegate Object
      4. Calling a Delegate
      5. Combining Delegate Objects
      6. Complete Example
      7. Stock Market Simulation
        1. Running the Simulation
        2. Delegate Code
        3. Passing the Delegates to the Engine
        4. Random-Number Generation
        5. Using the Delegates
        6. Events
      8. Events in C# and .NET
      9. Server-Side Event Code
      10. Client-Side Event Code
      11. Chat Room Example
        1. Client Code
        2. Server Code
    7. Attributes
      1. Attributes in .NET
        1. Preprocessor Symbols Using Compiler Option
        2. Using Attributes
        3. Attribute Targets
    8. Summary
  11. 6. User Interface Programming
    1. Windows Forms Hierarchy
    2. Simple Forms Using .NET SDK
      1. Step 0:. A Simple Form
        1. Windows Messages
      2. Step 1:. Drawing Text on a Form
        1. Windows Forms Event Handling
      3. Events Documentation
      4. MouseDown Event
      5. Step 2:. Handling a Mouse Event
      6. Step 2M:. Multiple Event Handlers
      7. Step 3:. MouseDown and KeyPress Events
        1. HAndling Left and Right Buttons
        2. KeyPress Event
    3. Menus
      1. Step 4:. A Menu to Exit the Program
      2. Menu Code
      3. Menu Event Code
    4. Controls
      1. Step 5:. Using a TextBox Control
    5. Visual Studio.NET and Forms
      1. Windows Forms Demonstration
      2. Design Window and Code Window
      3. Adding an Event
      4. Code for Event Handler
      5. Using the Menu Control
      6. Closing a Form
    6. Dialog Boxes
      1. .NET Dialog Documentation
      2. Dialog Box Demonstration
        1. Creating a Modal Dialog
        2. Passing Information Between Parent Form and a Dialog
    7. ListBox Control
      1. Populating a ListBox
      2. Selecting an Item From a ListBox
    8. Acme Travel Agency Case Study—Step 3
    9. Summary
  12. 7. Assemblies and Deployment
    1. Assemblies
      1. Contents of an Assembly
      2. Versioning an Assembly
      3. Strong Names
      4. Digital Signatures
      5. Digitally Signing an Assembly
    2. Private Assembly Deployment
    3. Shared Assembly Deployment
      1. Deploying a Shared Assembly
      2. Versioning Shared Components
    4. Assembly Configuration
      1. Resolving an Assembly Reference at Runtime
      2. Specifying the Version Policy in a Configuration File
      3. Finding the Assembly’s Physical Location
      4. Assembly Location and Visual Studio.NET
    5. Multimodule Assemblies
    6. Setup and Deployment Projects
      1. CAB Project
      2. Setup Project
      3. Merge Module Project
      4. Web-based Deployment
    7. Summary
  13. 8. .NET Framework Classes
    1. Metadata and Reflection
      1. Type
      2. Late Binding
    2. Input and Output in .NET
      1. Streams
      2. Primitive Datatypes and Streams
      3. TextReader and TextWriter
      4. File Manipulation
        1. File Class
        2. Path Class
        3. FileInfo Class
        4. File Example
    3. Serialization
      1. Serialization Objects
      2. ISerializable
    4. .NET Application Model
      1. Threads
        1. Thread Synchronization
        2. Synchronization with Monitors
        3. Notification with Monitors
        4. Synchronization Classes
        5. Automatic Synchronization
      2. Thread Isolation
      3. Synchronization of Collections
    5. Context
      1. Proxies and Stubs
      2. ContextBoundObject
    6. Application Isolation
      1. Application Domain
      2. Application Domains and Assemblies
      3. AppDomain Class
      4. App Domain Events
      5. AppDomain Example
      6. Marshaling, AppDomains, and Contexts
    7. Asynchronous Programming
      1. The Asynchronous Design Pattern
      2. IAsyncResult
      3. Using Delegates for Asynchronous Programming
        1. Begin/End Invoke
        2. Asynchronous Callback
      4. Threading with Parameters
    8. Remoting
      1. Remoting Overview
        1. Interception
        2. Channels And Formatters
      2. Remote Objects
      3. Activation
      4. Sample Remotable Object
        1. Sample Remoting Program
      5. Metadata and Remoting
      6. Remoting Configuration Files
    9. Custom Attributes
      1. Using a Custom Attribute
      2. Defining an Attribute Class
      3. Defining a Base Class
    10. Garbage Collection and Finalization
      1. Finalize
        1. C# Destructor Notation
        2. Limitations of Finalization
      2. Unmanaged Resources and Dispose
        1. Alternate Name for Dispose
      3. Garbage Collection and Generations
        1. Generations
      4. Finalization and Stack Unwinding
      5. Controlling Garbage Collection with the GC Class
        1. SuppressFinalize
        2. Collect
        3. MaxGeneration
        4. GetGeneration
        5. GetTotalMemory
      6. Sample Program
    11. Summary
  14. 9. Programming with ADO.NET
    1. .NET Data Providers
    2. The Visual Studio.NET Server Explorer
    3. Data Readers
      1. The Connected Database Scenario
      2. Executing SQL Statements
      3. DataReader
      4. Multiple Result Sets
    4. Parameters Collection
    5. SqlDataAdapter and the DataSet Class
      1. Disconnected Mode
    6. DataSet Collections
    7. DataSet Fundamentals
      1. Updating the Data Source
      2. Auto Generated Command Properties
    8. Database Transactions and Updates
    9. Optimistic vs. Pessimistic Locking and the DataSet
    10. Working with DataSets
      1. Multiple Tables in a DataSet
      2. Table Creation without a Data Source
      3. Constraints and Relations
        1. Primary Keys
        2. Constraints
        3. Data Relations
      4. Examining the Schema Information about a DataTable
      5. Database Events
        1. Navigating Relationships
      6. DataRow Editing
        1. BeginEdit, EndEdit, CancelEdit
        2. DataRow Versions
        3. DataRow RowState Property
        4. Accepting and Rejecting Changes
        5. DataRow Errors
    11. Acme Travel Agency Case Study
    12. XML Data Access
      1. XML Schema and Data
      2. XmlDataDocument
      3. DataSet and XML
    13. AirlineBrokers Database
      1. DataSet and XML
      2. Creating an XML Doc from a Dataset
    14. Schema with Relationships
    15. Typed DataSet
      1. Generating Typed DataSets
      2. Fetching Data with a Typed DataSet
      3. Displaying Data with a Typed Dataset
      4. Modify Data with a Typed Dataset
    16. Summary
  15. 10. ASP.NET and Web Forms
    1. What Is ASP.NET?
      1. Web Application Fundamentals
        1. Setting up the Web Examples
      2. An Echo Program
      3. ASP.NET Features
        1. Compiled Code
        2. Server Controls
        3. Browser Independence
        4. Separation of Code and Content
        5. State Management
    2. Web Forms Architecture
      1. Page Class
        1. Inheriting from Page Class
      2. Web Forms Page Life Cycle
      3. View State
      4. Web Forms Event Model
      5. Page Processing
        1. Page Events
        2. Page Properties
        3. Sample Program
      6. Page Directive
        1. Src
        2. Language
        3. Inherits
        4. Debug
        5. ErrorPage
        6. Trace
      7. Tracing
    3. Request/Response Programming
      1. HttpRequest Class
        1. Collections
        2. Example Program
      2. HttpResponse Class
        1. Redirect
    4. Web Applications Using Visual Studio.NET
      1. Hotel Information Web Page (Step 0)
        1. Configuring Web Server Connection
        2. Creating an ASP.NET Web Application
        3. Using the Form Designer
        4. Initializing the HotelBroker
        5. Data Binding
        6. Initializing the Hotels
        7. Selecting a City
        8. AutoPostBack
        9. Debugging
      2. Deploying a Web Application Created Using Visual Studio
        1. Using Project | Copy Project...
        2. Precompiled Web Page
        3. Inherits Attribute in Page Directive
        4. Configuring a Virtual Directory as an Application
        5. Moving a Visual Studio ASP.NET Web Application Project
    5. Acme Travel Agency Case Study
      1. Configuring the Case Study
      2. Acme Web Site Step 1
        1. HotelReservations.Aspx
        2. ManageReservations.Aspx
      3. Acme Web Site Step 2
        1. AcmeLib Component
        2. Login.Aspx
        3. RegisterNewUser.Aspx
        4. Main.Aspx
    6. ASP.NET Applications
      1. Sessions
      2. Global.asax
    7. State in ASP.NET Applications
      1. Static Data Members
      2. Application Object
      3. Session Object
        1. Session State and Cookies
        2. Session State Timeout
        3. Session State Store
    8. ASP.NET Configuration
      1. Configuration Files
        1. Server Configuration File
        2. Application Configuration Files
        3. Configuration File Format
      2. Application Tracing
      3. Session Configuration
    9. Server Controls
      1. Web Controls
    10. HTML Server Controls
      1. Html Controls Example
      2. HTML Controls in Visual Studio
      3. Validation Controls
        1. Required Field Validation
        2. Regular Expression Validation
      4. Rich Controls
    11. Database Access in ASP.NET
      1. Data Binding in ASP.NET
        1. Binding to an Arraylist
        2. Binding to a Datatable
      2. Acme Travel Agency Case Study (Database Version)
        1. AcmeCustomerDatabase
        2. AcmeLibDb Component
        3. Acme Web Site (Step 3)
    12. Summary
  16. 11. Web Services
    1. Protocols
      1. XML
      2. XML Namespaces
      3. XML Schema
      4. SOAP
      5. WSDL
    2. Web Service Architecture
      1. The Add Web Service Example
      2. A Client Program for the Add Web Service
      3. WSDL
      4. Proxy Classes
      5. Web Service Client with Raw SOAP and HTTP
    3. SOAP Differences
    4. Web Service Class
    5. Hotel Broker Web Service
      1. Customer Web Service
      2. Hotel Broker Web Service
      3. Design Considerations
    6. Summary
  17. 12. Security
    1. User-Based Security
    2. Code Access Security
      1. Security Policy
      2. Permissions
    3. Internet Security
      1. Internet Information Server
    4. Role-Based Security in .NET
      1. Principals and Identities
      2. .NET Windows Roles
      3. Other Identity Classes
      4. ASP.NET Roles
      5. Operating System Identity and CLR Identity
        1. Unauthenticated Users
        2. Authenticated Users
        3. Problems with Impersonation
      6. Specifying Users and Groups for Access in Web.Config
    5. Forms-Based Authentication
      1. Forms Authentication and Authorization
      2. Database Login Validation
    6. Code Access Permissions
      1. Simple Permission Code Request
      2. How a Permission Request Works
      3. Strategy for Requesting Permissions
      4. Denying Permissions
      5. Asserting Permissions
      6. Other Permission Methods
      7. SecurityPermission Class
      8. Unmanaged Code
      9. Attribute-Based Permissions
      10. Principal Permission
      11. PermissionSet
    7. Code Identity
      1. Identity Permission Classes
      2. Evidence
    8. Security Policy
      1. Security Policy Levels
      2. Code Groups
      3. Named Permission Sets
      4. Altering Security Policy
    9. Summary
  18. 13. Tracing and Debugging in .NET
    1. The TraceDemo Example
    2. Enabling Debug and Trace Output
    3. Using the Debug and Trace Classes
    4. Using Switches to Enable Diagnostics
    5. Enabling or Disabling Switches
      1. Configuration File Switch Settings
      2. Programmatic Switch Settings
      3. Using Switches to Control Output
    6. TraceListener
    7. Listeners Collection
    8. Summary
  19. 14. Interoperability
    1. Calling COM Components from Managed Code
      1. The Tlbimp.exe Utility
      2. Demonstration: Wrapping a Legacy COM Server
        1. Register the COM Server
        2. Run the COM Client
        3. Import the Type Library (TlbImp.exe)
        4. Implement the .NET Client Program
        5. Import a Type Library Using Visual Studio
      3. Wrapping a COM Component with a Pure Vtable Interface
        1. Dual Interfaces
        2. Pure Vtable Interface
    2. Calling Managed Components from COM Client
      1. A Late Binding COM Client
    3. Platform Invocation Services (PInvoke)
      1. A Simple Example
      2. Marshaling out Parameters
        1. Translating Types
    4. Summary
  20. A. Visual Studio.NET
    1. Overview of Visual Studio.NET
      1. Toolbars
        1. Customizing a Toolbar
    2. Creating a Console Application
      1. Creating a C# Project
      2. Adding a C# File
      3. Using the Visual Studio Text Editor
      4. Building the Project
      5. Running the Program
      6. Running the Program in the Debugger
    3. Project Configurations
      1. Creating a New Configuration
      2. Setting Build Settings for a Configuration
    4. Debugging
      1. Just-in-Time Debugging
      2. Standard Debugging
        1. Breakpoints
        2. Watching Variables
        3. Debugger Options
        4. Single Stepping
    5. Summary