C# and the .NET Platform
, by Troelsen, AndrewNote: Supplemental materials are not guaranteed with Rental or Used book purchases.
- ISBN: 9781590590553 | 1590590554
- Cover: Hardcover
- Copyright: 6/1/2003
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.
About the Author | p. xxi |
Acknowledgments | p. xxiii |
Introduction | p. xxv |
Introducing C# and the .NET Platform | p. 1 |
The Philosophy of .NET | p. 3 |
Understanding the Previous State of Affairs | p. 3 |
The .NET Solution | p. 6 |
The Building Blocks of the .NET Platform (CLR, CTS, and CLS) | p. 7 |
The Role of the .NET Base Class Libraries | p. 7 |
What C# Brings to the Table | p. 8 |
Additional .NET-Aware Programming Languages | p. 9 |
An Overview of .NET Binaries (aka Assemblies) | p. 11 |
The Role of the Common Intermediate Language | p. 13 |
The Role of .NET Type Metadata | p. 16 |
The Role of the Assembly Manifest | p. 17 |
Compiling CIL to Platform-Specific Instructions | p. 18 |
Understanding the Common Type System | p. 18 |
Intrinsic CTS Data Types | p. 22 |
Understanding the Common Language Specification | p. 23 |
Understanding the Common Language Runtime | p. 25 |
A Tour of the . NET Namespaces | p. 28 |
Increasing Your Namespace Nomenclature | p. 33 |
Deploying the .NET Runtime | p. 39 |
Summary | p. 41 |
Building C# Applications | p. 43 |
The Role of the Command Line Compiler (csc.exe) | p. 43 |
Building a C# Application Using csc.exe | p. 45 |
Working with csc.exe Response Files | p. 50 |
Generating Bug Reports | p. 52 |
Remaining C# Compiler Options | p. 54 |
The Command Line Debugger (cordbg.exe) | p. 55 |
Using the Visual Studio .NET IDE | p. 57 |
Building a VS .NET Test Application | p. 61 |
Debugging with the Visual Studio .NET IDE | p. 70 |
Other Key Aspects of the VS .NET IDE | p. 71 |
Documenting Your Source Code via XML | p. 76 |
C# ""Preprocessor"" Directives | p. 82 |
An Interesting Aside: The System.Environment Class | p. 88 |
Building .NET Applications with Other IDEs | p. 89 |
Summary | p. 90 |
The C# Programming Language | p. 91 |
C# Language Fundamentals | p. 93 |
The Anatomy of a Basic C# Class | p. 93 |
Creating Objects: Constructor Basics | p. 97 |
The Composition of a C# Application | p. 100 |
Default Assignments and Variable Scope | p. 102 |
The C# Member Variable Initialization Syntax | p. 104 |
Basic Input and Output with the Console Class | p. 105 |
Understanding Value Types and Reference Types | p. 109 |
The Master Node: System.Object | p. 115 |
The System Data Types (and C# Aliases) | p. 122 |
Converting Between Value Types and Reference Types: Boxing and Unboxing | p. 128 |
Defining Program Constants | p. 132 |
C# Iteration Constructs | p. 134 |
C# Control Flow Constructs | p. 137 |
The Complete Set of C# Operators | p. 139 |
Defining Custom Class Methods | p. 140 |
Understanding Static Methods | p. 143 |
Method Parameter Modifiers | p. 147 |
Array Manipulation in C# | p. 154 |
String Manipulation in C# | p. 160 |
C# Enumerations | p. 164 |
Defining Structures in C# | p. 168 |
Defining Custom Namespaces | p. 171 |
Summary | p. 176 |
Object-Oriented Programming with C# | p. 179 |
Formal Definition of the C# Class | p. 179 |
Defining the ""Default Public Interface"" of a Type | p. 184 |
Recapping the Pillars of OOP | p. 186 |
The First Pillar: C#'s Encapsulation Services | p. 191 |
Pseudo-Encapsulation: Creating Read-Only Fields | p. 199 |
The Second Pillar: C#'s Inheritance Support | p. 201 |
Keeping Family Secrets: The ""protected"" Keyword | p. 205 |
Nested Type Definitions | p. 211 |
The Third Pillar: C#'s Polymorphic Support | p. 213 |
Casting Between Types | p. 222 |
Generating Class Definitions Using Visual Studio .NET | p. 225 |
Summary | p. 229 |
Exceptions and Object Lifetime | p. 231 |
Ode to Errors, Bugs, and Exceptions | p. 231 |
The Role of .NET Exception Handling | p. 232 |
The System.Exception Base Class | p. 234 |
Throwing a Generic Exception | p. 235 |
Catching Exceptions | p. 236 |
CLR System-Level Exceptions (System.SystemException) | p. 240 |
Custom Application-Level Exceptions (System.ApplicationException) | p. 243 |
Handling Multiple Exceptions | p. 247 |
The Finally Block | p. 250 |
The Last Chance Exception | p. 251 |
Dynamically Identifying Application- and System-Level Exceptions | p. 252 |
Debugging System Exceptions Using VS .NET | p. 253 |
Understanding Object Lifetime | p. 257 |
The CIL of ""new"" | p. 257 |
The Basics of Garbage Collection | p. 259 |
Finalizing a Type | p. 260 |
The Finalization Process | p. 263 |
Building an Ad Hoc Destruction Method | p. 264 |
Garbage Collection Optimizations | p. 267 |
The System.GC Type | p. 267 |
Summary | p. 272 |
Interfaces and Collections | p. 273 |
Defining Interfaces Using C# | p. 273 |
Invoking Interface Members at the Object Level | p. 277 |
Exercising the Shapes Hierarchy | p. 279 |
Understanding Explicit Interface Implementation | p. 281 |
Interfaces As Polymorphic Agents | p. 284 |
Building Interface Hierarchies | p. 285 |
Implementing Interfaces Using VS .NET | p. 288 |
Understanding the IConvertible Interface | p. 290 |
Building a Custom Enumerator (IEnumerable and IEnumerator) | p. 293 |
Building Cloneable Objects (ICloneable) | p. 297 |
Building Comparable Objects (IComparable) | p. 302 |
Exploring the System.Collections Namespace | p. 306 |
Building a Custom Container (Retrofitting the Cars Type) | p. 315 |
Summary | p. 318 |
Callback Interfaces, Delegates, and Events | p. 321 |
Understanding Callback Interfaces | p. 321 |
Understanding the .NET Delegate Type | p. 325 |
Members of System.MulticastDelegate | p. 328 |
The Simplest Possible Delegate Example | p. 329 |
Building a More Elaborate Delegate Example | p. 333 |
Understanding Asynchronous Delegates | p. 341 |
Understanding (and Using) Events | p. 347 |
Summary | p. 354 |
Advanced C# Type Construction Techniques | p. 355 |
The Advanced Keywords of C# | p. 355 |
A Catalog of C# Keywords | p. 367 |
Building a Custom Indexer | p. 370 |
A Variation of the Cars Indexer | p. 372 |
Internal Representation of Type Indexers | p. 373 |
Using the C# Indexer from VB .NET | p. 374 |
Overloading Operators | p. 375 |
The Internal Representation of Overloaded Operators | p. 380 |
Interacting with Overloaded Operators from Overloaded-Operator-Challenged Languages | p. 383 |
Final Thoughts Regarding Operator Overloading | p. 385 |
Understanding Custom Type Conversions | p. 386 |
Creating Custom Conversion Routines | p. 387 |
Defining Implicit Conversion Routines | p. 390 |
The Internal Representation of Custom Conversion Routines | p. 391 |
Summary | p. 392 |
Programming with .NET Assemblies | p. 393 |
Understanding .NET Assemblies | p. 395 |
Problems with Classic COM Binaries | p. 395 |
An Overview of .NET Assemblies | p. 397 |
Building a Single File Test Assembly | p. 404 |
A C# Client Application | p. 408 |
A Visual Basic .NET Client Application | p. 409 |
Cross-Language Inheritance | p. 411 |
Exploring the CarLibrary's Manifest | p. 415 |
Exploring the CarLibrary's Types | p. 418 |
Building a Multifile Assembly | p. 419 |
Using the Multifile Assembly | p. 422 |
Understanding Private Assemblies | p. 425 |
Probing for Private Assemblies (The Basics) | p. 425 |
Private Assemblies and XML Configuration Files | p. 426 |
Probing for Private Assemblies (The Details) | p. 429 |
Understanding Shared Assemblies | p. 430 |
Understanding Strong Names | p. 431 |
Building a Shared Assembly | p. 432 |
Understanding Delayed Signing | p. 434 |
Installing/Removing Shared Assemblies | p. 435 |
Using a Shared Assembly | p. 436 |
Versioning Shared Assemblies | p. 437 |
Building SharedAssembly Version 2.0.0.0 | p. 438 |
Specifying Custom Version Policies | p. 440 |
GAC Internals | p. 440 |
Assembly-Centric Odds and Ends | p. 442 |
Regarding the VS .NET Add References Dialog Box | p. 449 |
Summary | p. 450 |
Processes, AppDomains, Contexts, and Threads | p. 451 |
Reviewing Processes and Threads Under Traditional Win32 | p. 451 |
Interacting with Processes Under the .NET Platform | p. 453 |
Understanding the System.AppDomain Type | p. 462 |
Understanding Context (or How Low Can You Go?) | p. 468 |
Summarizing Processes, AppDomains, and Context | p. 474 |
The Process/AppDomain/Context/Thread Relationship | p. 474 |
Multithreaded Programming via Delegates | p. 476 |
The System. Threading Namespace | p. 476 |
Spawning Secondary Threads | p. 481 |
A More Elaborate Threading Example | p. 484 |
Concurrency Revisited | p. 487 |
Synchronization Using the C# ""lock"" Keyword | p. 490 |
Synchronization Using the System. Threading.Interlocked Type | p. 492 |
Synchronization Using the [Synchronized] Attribute | p. 493 |
Thread Safety and the .NET Base Class Libraries | p. 494 |
Programming with Timer Callbacks | p. 494 |
Summary | p. 496 |
Type Reflection, Late Binding, and Attribute-Based Programming | p. 499 |
The Necessity of Type Metadata | p. 499 |
Understanding Reflection | p. 504 |
The System.Type Class | p. 504 |
Investigating the System.Reflection Namespace | p. 511 |
Reflecting on a Private Assembly | p. 511 |
Reflecting on Shared Assemblies | p. 516 |
Understanding Dynamic Invocation (Late Binding) | p. 517 |
Understanding Attributed Programming | p. 520 |
Building Custom Attributes | p. 523 |
Restricting Attribute Usage | p. 524 |
Assembly- (and Module-) Level Attributes | p. 526 |
Reflecting on Attributes at Runtime | p. 528 |
Putting Reflection, Late Binding, and Custom Attributes in Perspective | p. 528 |
Summary | p. 535 |
Leveraging the .NET Libraries | p. 537 |
Object Serialization and the .NET Remoting Layer | p. 539 |
Object Persistence in the .NET Framework | p. 540 |
The Role of Object Graphs | p. 540 |
Configuring Objects for Serialization | p. 541 |
Serialization Using a Binary Formatter | p. 545 |
Serialization Using a SOAP Formatter | p. 547 |
Serialization Using an XML Formatter | p. 548 |
Customizing the Serialization Process | p. 549 |
Defining .NET Remoting | p. 554 |
The .NET Remoting Namespaces | p. 554 |
Understanding the .NET Remoting Framework | p. 556 |
All Together Now! | p. 559 |
Terms of the .NET Remoting Trade | p. 560 |
Object Marshaling Choices (MBR or MBV?) | p. 560 |
Final Notes Regarding MBR/MBV Objects | p. 563 |
Activation Choices for MBR Types (WKO or CAO?) | p. 563 |
Basic Deployment of a .NET Remoting Project | p. 566 |
Building Our First Distributed Application | p. 568 |
Testing the Remoting Application | p. 571 |
Understanding the ChannelServices Type | p. 572 |
Understanding the RemotingConfiguration Type | p. 573 |
Revisiting the Activation Mode of WKO Types | p. 576 |
Deploying the Server to a Remote Machine | p. 577 |
Leveraging the TCP Channel | p. 578 |
Remoting Configuration Files | p. 579 |
Working with MBV Objects | p. 582 |
Understanding Client-Activated Objects (CAO) | p. 587 |
The Lease-Based Lifetime of CAO/WKO-Singleton Objects | p. 589 |
Server-side (and Client-side) Lease Sponsorship | p. 595 |
Alternative Hosts for Remote Objects | p. 597 |
Asynchronous Remoting | p. 603 |
The Role of the [OneWayAttribute] Type | p. 604 |
Final Thoughts | p. 605 |
Summary | p. 606 |
Building a Better Window (Introducing Windows Forms) | p. 607 |
A Tale of Three GUI Namespaces | p. 607 |
Overview of the System.Windows.Forms Namespace | p. 608 |
Interacting with the Windows Forms Types | p. 609 |
Building a VS .NET Windows Forms Project Workspace | p. 612 |
The System.Windows.Forms.Application Class | p. 615 |
The Anatomy of a Form | p. 621 |
The Component Class | p. 622 |
The Control Class | p. 623 |
Control Events | p. 627 |
Responding to Keyboard Events | p. 631 |
The Control Class Revisited | p. 633 |
The ScrollableControl Class | p. 636 |
ContainerControl Class | p. 637 |
The Form Class | p. 637 |
The Life-Cycle of a Windows Form Type | p. 640 |
Handing Form Level Events a la VS .NET | p. 643 |
Building Menus with Windows Forms | p. 644 |
Building Your Menu System | p. 646 |
Creating a Pop-Up Menu | p. 649 |
Adorning Your Menu System | p. 651 |
Building a Menu Using Visual Studio .NET | p. 654 |
Understanding Status Bars | p. 655 |
Building a Tool Bar | p. 660 |
Building ToolBars at Design Time | p. 664 |
Building an MDI Application | p. 666 |
Summary | p. 669 |
A Better Painting Framework (GDI+) | p. 671 |
Survey of the GDI+ Namespaces | p. 671 |
Overview of the System.Drawing Namespace | p. 673 |
Examining the System.Drawing Utility Types | p. 675 |
Regarding the Disposal of System.Drawing Types | p. 680 |
Understanding Paint Sessions | p. 680 |
Understanding the Graphics Class | p. 685 |
The GDI+ Coordinate Systems | p. 687 |
Establishing an Active Color | p. 692 |
Manipulating Fonts | p. 695 |
Building a Font Application | p. 698 |
The FontDialog Class | p. 703 |
Survey of the System.Drawing.Drawing2D Namespace | p. 705 |
Rendering Images | p. 720 |
Dragging, Hit Testing, and the PictureBox Control | p. 723 |
Understanding the .NET Resource Format | p. 732 |
System.Resources Namespace | p. 733 |
Working with ResourceWriters | p. 737 |
Working with ResourceManagers | p. 737 |
Automatic Resource Configuration a la Visual Studio .NET | p. 739 |
Summary | p. 742 |
Programming with Windows Forms Controls | p. 743 |
Understanding the Windows Forms Control Hierarchy | p. 743 |
Adding Controls to Forms (IDE-Free) | p. 744 |
Adding Controls to Forms (via VS .NET) | p. 747 |
The TextBox Control | p. 749 |
The Mighty Button Type | p. 752 |
Working with CheckBoxes | p. 755 |
Working with RadioButtons and GroupBoxes | p. 756 |
ListBoxes and ComboBoxes | p. 761 |
The MonthCalendar Control | p. 763 |
More on the DateTime Type | p. 766 |
Setting the Form's Default Input Button | p. 767 |
Configuring the Tab Order | p. 768 |
Assigning ToolTips to Controls | p. 769 |
The TrackBar Control | p. 770 |
Working with Panel Controls | p. 773 |
The UpDown Controls: DomainUpDown and NumericUpDown | p. 774 |
Working with the ErrorProvider | p. 776 |
Configuring a Control's Anchoring Behavior | p. 779 |
Configuring a Control's Docking Behavior | p. 780 |
Building Custom Dialog Boxes | p. 781 |
Understanding Form Inheritance | p. 787 |
Building Custom Windows Forms Controls | p. 789 |
Building a Custom UserControl | p. 790 |
Creating the Images | p. 791 |
Building the Design Time GUI | p. 792 |
Implementing the CarControl | p. 792 |
Controlling the Animation | p. 796 |
Rendering the Pet Name | p. 796 |
Testing the CarControl Type | p. 797 |
Select Members of the System.ComponentModel Namespace | p. 798 |
Enhancing the Design Time Appearance of CarControl | p. 800 |
Summary | p. 803 |
The System.IO Namespace | p. 805 |
Exploring the System.IO Namespace | p. 805 |
The Directory(Info) and File(Info) Types | p. 806 |
Enumerating Files with the Directorylnfo Type | p. 810 |
Creating Subdirectories with the Directorylnfo Type | p. 811 |
The Static Members of the Directory Class | p. 812 |
The Filelnfo Class | p. 814 |
The Abstract Stream Class | p. 818 |
Working with StreamWriters and StreamReaders | p. 822 |
Working with StringWriters | p. 826 |
Working with StringReaders | p. 828 |
Working with Binary Data (BinaryReaders and BinaryWriters) | p. 829 |
""Watching"" Files and Directories | p. 831 |
A Brief Word Regarding Asynchronous IO | p. 833 |
A Windows Forms Car Logger Application | p. 834 |
Summary | p. 841 |
Data Access with ADO.NET | p. 843 |
The Need for ADO.NET | p. 843 |
The Two Faces of ADO.NET | p. 844 |
The Role of ADO.NET Data Providers | p. 845 |
Understanding the ADO.NET Namespaces | p. 850 |
The Types of System.Data | p. 851 |
Examining the DataColumn Type | p. 852 |
Examining the DataRow Type | p. 858 |
Details of the DataTable | p. 861 |
Building a Complete DataTable | p. 863 |
Understanding the DataView Type | p. 871 |
Understanding the Role of the DataSet | p. 874 |
Expressing Relations Using the DataRelation Type | p. 879 |
Reading and Writing XML-Based DataSets | p. 883 |
Building a Simple Test Database | p. 886 |
Selecting a Data Provider | p. 887 |
The Types of the System.Data.OleDb Namespace | p. 888 |
Working with the Connected Layer of ADO.NET | p. 888 |
Working with the OleDbDataReader | p. 894 |
Inserting, Updating, and Deleting Records Using OleDbCommand | p. 897 |
Executing a Stored Procedure Using OleDbCommand | p. 899 |
The Disconnected Layer and the OleDbDataAdapter Type | p. 901 |
Working with the SQL Data Provider | p. 906 |
Auto-Generating SQL Commands Using CommandBuilder Types | p. 912 |
A Complete ADO.NET Windows Forms Example | p. 914 |
Filling a Multitabled DataSet (and Adding DataRelations) | p. 916 |
Bring In the Wizards! | p. 919 |
Working with DataSets at Design Time | p. 927 |
Summary | p. 931 |
Web Applications and XML Web Services | p. 933 |
ASP.NET Web Pages and Web Controls | p. 935 |
The Role of HTTP | p. 935 |
Understanding Web Applications and Web Servers | p. 936 |
The Role of HTML | p. 939 |
HTML Form Development | p. 940 |
The Role of Client-Side Scripting | p. 943 |
Submitting the Form Data (GET and POST) | p. 947 |
Building a Classic Active Server Page | p. 947 |
The Problem(s) with Classic ASP | p. 950 |
Some Benefits of ASP.NET | p. 950 |
The ASP.NET Namespaces | p. 952 |
Creating an ASP.NET Web Application by Hand | p. 953 |
The ASP.NET Compilation Cycle | p. 958 |
Creating an ASP.NET Web Application via VS .NET | p. 961 |
Coding the BetterAspNetCarApp Web Application | p. 966 |
The Composition of an ASP.NET Page | p. 968 |
The Derivation of an ASP.NET Page | p. 970 |
Interacting with the Incoming HTTP Request | p. 971 |
Interacting with the Outgoing HTTP Response | p. 975 |
The Life Cycle of an ASP.NET Web Page | p. 978 |
Understanding the ASP.NET Web Controls | p. 982 |
Key Members of the System.Web.UI.Control Type | p. 985 |
Key Members of the System.Web.UI.WebControl Type | p. 990 |
Select Examples of ASP.NET WebForm Controls | p. 991 |
The Role of the Validation Controls | p. 1005 |
Understanding the Role of ASP.NET HTML Controls | p. 1014 |
And Now for Something Completely Different: GDI+ on the Web Server | p. 1016 |
Debugging and Tracing ASP.NET Pages | p. 1020 |
Summary | p. 1021 |
ASP.NET Web Applications | p. 1023 |
The Issue of State | p. 1023 |
ASP.NET State Management Techniques | p. 1026 |
Understanding the Role of ASP.NET View State | p. 1026 |
The Role of the Clobal.asax File | p. 1030 |
Understanding the Application/Session Distinction | p. 1033 |
Working with the Application Cache | p. 1037 |
Maintaining Session Data | p. 1043 |
Understanding Cookies | p. 1047 |
Configuring Your ASP.NET Web Application Using web.config | p. 1050 |
Configuration Inheritance | p. 1057 |
Summary | p. 1058 |
XML Web Services | p. 1059 |
Understanding the Role of XML Web Services | p. 1059 |
The Building Blocks of an XML Web Service | p. 1062 |
The .NET XML Web Service Namespaces | p. 1064 |
Examining the System.Web.Services Namespace | p. 1064 |
Building an XML Web Service in the Raw | p. 1065 |
Testing Your XML Web Service | p. 1066 |
Building an XML Web Service Using Visual Studio .NET | p. 1069 |
Understanding the System.Web.Services.WebService Base Class | p. 1072 |
Understanding the [WebMethod] Attribute | p. 1073 |
Understanding the [WebService] Attribute | p. 1077 |
Exploring the Web Service Description Language (WSDL) | p. 1078 |
The Basic Format of a WSDL Document | p. 1079 |
Viewing the HelloWS WSDL Document | p. 1082 |
The wsdl.exe Command Line Utility | p. 1084 |
Revisiting the XML Web Service Wire Protocols | p. 1086 |
Transforming WSDL into C# Code (Generating a Proxy) | p. 1089 |
Leveraging the Proxy (Synchronous Invocations) | p. 1092 |
Leveraging the Proxy (Asynchronous Invocations) | p. 1093 |
Avoiding Hard-Coded Proxy Logic | p. 1094 |
Generating a Proxy with VS .NET | p. 1095 |
Exposing Arrays of Types from Web Methods | p. 1096 |
A Windows Forms Client | p. 1097 |
Exposing Custom Types: The Details | p. 1098 |
Consuming Custom Types: The Details | p. 1099 |
Updating the CarsSaleslnfoWS Project | p. 1100 |
Understanding the Discovery Service Protocol (UDDI) | p. 1102 |
Summary | p. 1105 |
Index | p. 1107 |
Table of Contents provided by Publisher. All Rights Reserved. |
What is included with this book?
The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.
The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.