Andrew Troelsen
The mission of this book is to provide you with a solid foundation of the C# language and the key aspects of the .NET platform.
Introduction
The first edition of thise book was released during the 2001 TechEd conference in Atlanta, Georgia. Since then, C# and the .NET Platform has been translated into eight different languages, nominated as a 2002 Jolt Award Finalst, and named winner of the 2003 Referenceware Excellence Awards in the best programming book category.
For those of you who have read the first edition, we’re happy to report that the text has gone through a substantial upgrade. You will find that every chapter has been updated with additional fresh content. Several new chapters exist, including coverage of the .NET Remoting layer, core CLR atoms, and a much deeper treatment of ASP.NET. As always, the story is told using a friendly and approachable voice.
If you are checking out this book for the first time, understand that this text is intended for developers who already have some experience in a modern object language. The mission of this text is to provide you with a solid foundation of the C# language and the key aspects of the .NET platform (assemblies, Windows Forms, Web Forms, etc.). Once you read and absorb these twenty chapters, you will be in a perfect position to apply this knowldege to your specific programming assignments, and you will be well equipped to explore the .NET universe on your own terms.
Author Information
Andrew Troelsen is a partner, trainer, and consultant at Intertech-Inc., and is a leading authority on both .NET and COM. His book Pro C# 2005 and the .NET 2.0 Platform won the prestigious 2003 Referenceware Excellence Award and is now in its third edition. Also of note are his earlier five-star treatment of traditional COM in the bestselling Developer's Workshop to COM and ATL mirrored in his book, COM and .NET Interoperability, and his top-notch investigation of VB .NET in Visual Basic .NET and the .NET Platform: An Advanced Guide. Troelsen has a degree in mathematical linguistics and South Asian studies from the University of Minnesota and is a frequent speaker at numerous .NET-related conferences. He currently lives in Minneapolis, Minnesota, with his wife, Amanda, and spends his free time investigating .NET and waiting for the Wild to win the Stanley Cup.
What is in this book
About the Author
Acknowledgments
Understanding the Previous State of Affairs
The .NET Solution
The Building Blocks of the .NET Platform (CLR, CTS, and CLS)
The Role of the .NET Base Class Libraries
What C# Brings to the Table
Additional .NET-Aware Programming Languages
An Overview of .NET Binaries (aka Assemblies)
The Role of the Common Intermediate Language
The Role of .NET Type Metadata
The Role of the Assembly Manifest
Compiling CIL to Platform-Specific Instructions
Understanding the Common Type System
Intrinsic CTS Data Types
Understanding the Common Language Specification
Understanding the Common Language Runtime
A Tour of the .NET Namespaces
Increasing Your Namespace Nomenclature Deploying the .NET Runtime
Summary
The Role of the Command Line Compiler (csc.exe)
Building a C# Application Using csc.exe
Working with csc.exe Response Files
Generating Bug Reports
Remaining C# Compiler Options
The Command Line Debugger (cordbg.exe)
Using the Visual Studio .NET IDE
Building a VS .NET Test Application
Debugging with the Visual Studio .NET IDE
Other Key Aspects of the VS .NET IDE
Documenting Your Source Code via XML
C# “Preprocessor” Directives
An Interesting Aside: The System.Environment Class
Building .NET Applications with Other IDEs
The Anatomy of a Basic C# Class
Creating Objects: Constructor Basics
The Composition of a C# Application
Default Assignments and Variable Scope
The C# Member Variable Initialization Syntax
Basic Input and Output with the Console Class
Understanding Value Types and Reference Types
The Master Node: System.Object
The System Data Types (and C# Aliases)
Converting Between Value Types and Reference Types: Boxing and Unboxing
Defining Program Constants
C# Iteration Constructs
C# Control Flow Constructs
The Complete Set of C# Operators
Defining Custom Class Methods
Understanding Static Methods
Method Parameter Modifiers
Array Manipulation in C#
String Manipulation in C#
C# Enumerations
Defining Structures in C#
Defining Custom Namespaces
Formal Definition of the C# Class
Defining the “Default Public Interface” of a Type
Recapping the Pillars of OOP
The First Pillar: C#’s Encapsulation Services
Pseudo-Encapsulation: Creating Read-Only Fields
The Second Pillar: C#’s Inheritance Support
Keeping Family Secrets: The “protected” Keyword
Nested Type Definitions
The Third Pillar: C#’s Polymorphic Support
Casting Between Types
Generating Class Definitions Using Visual Studio .NET
Ode to Errors, Bugs, and Exceptions
The Role of .NET Exception Handling
The System.Exception Base Class
Throwing a Generic Exception
Catching Exceptions
CLR System-Level Exceptions (System.SystemException)
Custom Application-Level Exceptions (System.ApplicationException)
Handling Multiple Exceptions
The Finally Block
The Last Chance Exception
Dynamically Identifying Application- and System-Level Exceptions
Debugging System Exceptions Using VS .NET
Understanding Object Lifetime
The CIL of “new”
The Basics of Garbage Collection
Finalizing a Type
The Finalization Process
Building an Ad Hoc Destruction Method
Garbage Collection Optimizations
The System.GC Type
Defining Interfaces Using C#
Invoking Interface Members at the Object Level
Exercising the Shapes Hierarchy
Understanding Explicit Interface Implementation
Interfaces As Polymorphic Agents
Building Interface Hierarchies
Implementing Interfaces Using VS .NET
Understanding the IConvertible Interface
Building a Custom Enumerator (IEnumerable and IEnumerator)
Building Cloneable Objects (ICloneable)
Building Comparable Objects (IComparable)
Exploring the System.Collections Namespace
Building a Custom Container (Retrofitting the Cars Type)
Understanding Callback Interfaces
Understanding the .NET Delegate Type
Members of System.MulticastDelegate
The Simplest Possible Delegate Example
Building a More Elaborate Delegate Example
Understanding Asynchronous Delegates
Understanding (and Using) Events
The Advanced Keywords of C#
A Catalog of C# Keywords
Building a Custom Indexer
A Variation of the Cars Indexer
Internal Representation of Type Indexers
Using the C# Indexer from VB .NET
Overloading Operators
The Internal Representation of Overloaded Operators
Interacting with Overloaded Operators from Overloaded-Operator-Challenged Languages Final Thoughts Regarding Operator Overloading
Understanding Custom Type Conversions
Creating Custom Conversion Routines
Defining Implicit Conversion Routines
The Internal Representation of Custom Conversion Routines
Problems with Classic COM Binaries
An Overview of .NET Assemblies
Building a Single File Test Assembly
A C# Client Application
A Visual Basic .NET Client Application
Cross-Language Inheritance
Exploring the CarLibrary’s Manifest
Exploring the CarLibrary’s Types
Building a Multifile Assembly
Using the Multifile Assembly
Understanding Private Assemblies
Probing for Private Assemblies (The Basics)
Private Assemblies and XML Configuration Files
Probing for Private Assemblies (The Details)
Understanding Shared Assemblies
Understanding Strong Names
Building a Shared Assembly
Understanding Delayed Signing
Installing/Removing Shared Assemblies
Using a Shared Assembly
Versioning Shared Assemblies
Building Shared Assembly Version 2.0.0.0
Specifying Custom Version Policies
GAC Internals
Assembly-Centric Odds and Ends
Regarding the VS .NET Add References Dialog Box
Reviewing Processes and Threads
Under Traditional Win32
Interacting with Processes Under the .NET Platform
Understanding the System.AppDomain Type
Understanding Context (or How Low Can You Go?)
Summarizing Processes, AppDomains, and Context
The Process/AppDomain/Context/Thread Relationship
Multithreaded Programming via Delegates
The System.Threading Namespace
Spawning Secondary Threads
A More Elaborate Threading Example
Concurrency Revisited
Synchronization Using the C# “lock” Keyword
Synchronization Using the System.Threading.Interlocked Type
Synchronization Using the [Synchronized] Attribute
Thread Safety and the .NET Base Class Libraries
Programming with Timer Callbacks
The Necessity of Type Metadata
Understanding Reflection
The System.Type Class
Investigating the System.Reflection Namespace
Reflecting on a Private Assembly
Reflecting on Shared Assemblies
Understanding Dynamic Invocation (Late Binding)
Understanding Attributed Programming
Building Custom Attributes
Restricting Attribute Usage
Assembly- (and Module-) Level Attributes
Reflecting on Attributes at Runtime
Putting Reflection, Late Binding, and Custom Attributes in Perspective
Object Persistence in the .NET Framework
The Role of Object Graphs
Configuring Objects for Serialization
Serialization Using a Binary Formatter
Serialization Using a SOAP Formatter
Serialization Using an XML Formatter
Customizing the Serialization Process
Defining .NET Remoting
The .NET Remoting Namespaces
Understanding the .NET Remoting Framework
All Together Now!
Terms of the .NET Remoting Trade
Object Marshaling Choices (MBR or MBV?)
Final Notes Regarding MBR/MBV Objects
Activation Choices for MBR Types (WKO or CAO?)
Basic Deployment of a .NET Remoting Project
Building Our First Distributed Application
Testing the Remoting Application
Understanding the ChannelServices Type
Understanding the RemotingConfiguration Type
Revisiting the Activation Mode of WKO Types
Deploying the Server to a Remote Machine
Leveraging the TCP Channel
Remoting Configuration Files
Working with MBV Objects
Understanding Client-Activated Objects (CAO)
The Lease-Based Lifetime of CAO/WKO-Singleton Objects
Server-side (and Client-side) Lease Sponsorship
Alternative Hosts for Remote Objects
Asynchronous Remoting
The Role of the [OneWayAttribute] Type
Final Thoughts
A Tale of Three GUI Namespaces
Overview of the System.Windows.Forms Namespace
Interacting with the Windows Forms Types
Building a VS .NET Windows Forms Project Workspace
The System.Windows.Forms.Application Class
The Anatomy of a Form
The Component Class
The Control Class
Control Events
Responding to Keyboard Events
The Control Class Revisited
The ScrollableControl Class
ContainerControl Class
The Form Class
The Life-Cycle of a Windows Form Type
Handing Form Level Events a la VS .NET
Building Menus with Windows Forms
Building Your Menu System
Creating a Pop-Up Menu
Adorning Your Menu System
Building a Menu Using Visual Studio .NET
Understanding Status Bars
Building a Tool Bar
Building ToolBars at Design Time
Building an MDI Application
Survey of the GDI+ Namespaces
Overview of the System.Drawing Namespace
Examining the System.Drawing Utility Types
Regarding the Disposal of System.Drawing Types
Understanding Paint Sessions
Understanding the Graphics Class
The GDI+ Coordinate Systems
Establishing an Active Color
Manipulating Fonts
Building a Font Application
The FontDialog Class
Survey of the System.Drawing.Drawing2D Namespace
Rendering Images
Dragging, Hit Testing, and the PictureBox Control
Understanding the .NET Resource Format
System.Resources Namespace
Working with ResourceWriters
Working with ResourceManagers
Automatic Resource Configuration a la Visual Studio .NET
Understanding the Windows Forms Control Hierarchy
Adding Controls to Forms (IDE-Free)
Adding Controls to Forms (via VS .NET)
The TextBox Control
The Mighty Button Type
Working with CheckBoxes
Working with RadioButtons and GroupBoxes
ListBoxes and ComboBoxes
The MonthCalendar Control
More on the DateTime Type
Setting the Form’s Default Input Button
Configuring the Tab Order
Assigning ToolTips to Controls
The TrackBar Control
Working with Panel Controls
The UpDown Controls: DomainUpDown and NumericUpDown
Working with the ErrorProvider
Configuring a Control’s Anchoring Behavior
Configuring a Control’s Docking Behavior
Building Custom Dialog Boxes
Understanding Form Inheritance
Building Custom Windows Forms Controls
Building a Custom UserControl
Creating the Images
Building the Design Time GUI
Implementing the CarControl
Controlling the Animation
Rendering the Pet Name
Testing the CarControl Type
Select Members of the System.ComponentModel Namespace
Enhancing the Design Time Appearance of CarControl
Exploring the System.IO Namespace
The Directory(Info) and File(Info) Types
Enumerating Files with the DirectoryInfo Type
Creating Subdirectories with the DirectoryInfo Type
The Static Members of the Directory Class
The FileInfo Class
The Abstract Stream Class
Working with StreamWriters and StreamReaders
Working with StringWriters
Working with StringReaders
Working with Binary Data (BinaryReaders and BinaryWriters)
“Watching” Files and Directories
A Brief Word Regarding Asynchronous IO
A Windows Forms Car Logger Application
The Need for ADO.NET
The Two Faces of ADO.NET
The Role of ADO.NET Data Providers
Understanding the ADO.NET Namespaces
The Types of System.Data
Examining the DataColumn Type
Examining the DataRow Type
Details of the DataTable
Building a Complete DataTable
Understanding the DataView Type
Understanding the Role of the DataSet
Expressing Relations Using the DataRelation Type
Reading and Writing XML-Based DataSets
Building a Simple Test Database
Selecting a Data Provider
The Types of the System.Data.OleDb Namespace
Working with the Connected Layer of ADO.NET
Working with the OleDbDataReader
Inserting, Updating, and Deleting Records Using OleDbCommand
Executing a Stored Procedure Using OleDbCommand
The Disconnected Layer and the OleDbDataAdapter Type
Working with the SQL Data Provider
Auto-Generating SQL Commands Using CommandBuilder Types
A Complete ADO.NET Windows Forms Example
Filling a Multitabled DataSet (and Adding DataRelations)
Bring In the Wizards!
Working with DataSets at Design Time
The Role of HTTP
Understanding Web Applications and Web Servers
The Role of HTML
HTML Form Development
The Role of Client-Side Scripting
Submitting the Form Data (GET and POST)
Building a Classic Active Server Page
The Problem(s) with Classic ASP
Some Benefits of ASP.NET
The ASP.NET Namespaces
Creating an ASP.NET Web Application by Hand
The ASP.NET Compilation Cycle
Creating an ASP.NET Web Application via VS .NET
Coding the BetterAspNetCarApp Web Application
The Composition of an ASP.NET Page
The Derivation of an ASP.NET Page
Interacting with the Incoming HTTP Request
Interacting with the Outgoing HTTP Response
The Life Cycle of an ASP.NET Web Page
Understanding the ASP.NET Web Controls
Key Members of the System.Web.UI.Control Type
Key Members of the System.Web.UI.WebControl Type
Select Examples of ASP.NET WebForm Controls
The Role of the Validation Controls
Understanding the Role of ASP.NET HTML Controls
And Now for Something Completely Different: GDI+ on the Web Server Debugging and Tracing ASP.NET Pages
The Issue of State
ASP.NET State Management Techniques
Understanding the Role of ASP.NET View State
The Role of the Global.asax File
Understanding the Application/Session Distinction
Working with the Application Cache
Maintaining Session Data
Understanding Cookies
Configuring Your ASP.NET Web Application Using web.config
Configuration Inheritance
Understanding the Role of XML Web Services
The Building Blocks of an XML Web Service
The .NET XML Web Service Namespaces
Examining the System.Web.Services Namespace
Building an XML Web Service in the Raw
Testing Your XML Web Service
Building an XML Web Service Using Visual Studio .NET
Understanding the System.Web.Services.WebService Base Class
Understanding the [WebMethod] Attribute
Understanding the [WebService] Attribute
Exploring the Web Service Description Language (WSDL)
The Basic Format of a WSDL Document
Viewing the HelloWS WSDL Document
The wsdl.exe Command Line Utility
Revisiting the XML Web Service Wire Protocols
Transforming WSDL into C# Code (Generating a Proxy)
Leveraging the Proxy (Synchronous Invocations)
Leveraging the Proxy (Asynchronous Invocations)
Avoiding Hard-Coded Proxy Logic
Generating a Proxy with VS .NET
Exposing Arrays of Types from Web Methods
A Windows Forms Client
Exposing Custom Types: The Details
Consuming Custom Types: The Details
Updating the CarsSalesInfoWS Project
Understanding the Discovery Service Protocol (UDDI)
Note:
Mindcracker Network accepts no liability for providing the customer with the hard copy of the book purchased. Mindcracker is not responsible for any dispute relating to the above. All eBooks listed in this section are in "PDF" Format. Contact [email protected] for further assistant.
Unlock unlimited ebook downloads. Share it on your social profile.