Register your product to gain access to bonus material or receive a coupon.
What do you need when you are coding in C#? If your answer is easily understood recipes for code that does something, then this is the book for you! You probably already have a handle on the basics of .NET programming and are in need of some shortcuts to make your job easier. How about 350 code recipes! The Microsoft Visual C# .NET 2003 Developer's Cookbook provides a practical reference for various programming tasks. Each chapter consists of a brief description of the topic at hand and then gives you the goods - recipes that explain a brief description of the task, the technique and comments about the technique chosen by C# experts, Mark Schmidt and Simon Robinson.
Strings and Regular Expressions
I. THE C# LANGUAGE.1. Operators, Expressions, and Control Structures.
Introduction. Understanding Visual C# .NET Program Layout. Parsing Command-Line Arguments. Creating Multiple Application Entry Points. Referencing Assemblies and Namespaces. Creating Valid Identifier Names. Working with Numeric Types. Working with Floating-Point Numbers. Creating Value Types with struct. Converting Data Types. Performing Relational Operations. Using Logical Expressions. Determining Operator Precedence and Associativity. Using if Statements. Using Looping Control Structures. Breaking Out of a Loop Control Body.2. Objects and Components.
Introduction. Creating Classes. Defining Class Fields. Constructing Class Methods. Instantiating and Using Objects. Overloading Operators. Overloading Class Constructors. Constructing Class Properties. Inheriting from Other Classes. Preventing Object Inheritance. String Representation of Objects. Abstract Classes and Interfaces. Multiple Inheritance Using Interfaces. Creating and Using Class Libraries.3. Strings and Regular Expressions.
Introduction. Creating and Using String Objects. Formatting Strings. Accessing Individual String Characters. Analyzing Character Attributes. Case-Insensitive String Comparison. Working with Substrings. Using Verbatim String Syntax. Choosing Between Constant and Mutable Strings. Optimizing StringBuilder Performance. Understanding Basic Regular Expression Syntax. Validating User Input with Regular Expressions. Replacing Substrings Using Regular Expressions. Building a Regular Expression Library.4. Creating and Using .NET Collections.
Introduction. Declaring and Using Arrays. Defining Jagged Arrays. Enumerating Arrays with the foreach Operator. Determining the Current Element Index Within a foreach Loop. Using ArrayLists. Choosing Between an Array and an ArrayList. Using Stacks and Queues. Using Hashtables. Working with BitArrays. Enumerating Collections with IEnumerator. Sorting Collections. Binary Searching with Arrays. Creating New Collection Types. Creating Indexers.5. Delegates and Events.
Introduction. Defining and Using Delegates. Combining Delegates to Form Multicast Delegates. Removing Individual Delegates from Multicast Delegates. Accessing Delegate Names Within a Multicast Delegate. Calling Delegates Asynchronously. Return Values for Multicast Delegates. Declaring Events. Defining and Registering Event Handlers. Packaging Event Arguments.6. Exceptions and Error Handling.
Introduction. Using try/catch blocks. Using a finally Block. Displaying Exception Information. Creating and Throwing Custom Exceptions. Accessing Inner Exceptions. Overflow Detection Using Checked and Unchecked.
II. USER INTERFACE AND GRAPHICS.7. Windows Forms.
Introduction. Creating a Dialog-Based Windows Form. Changing a Form's Properties. Creating Modal Dialog Boxes. Displaying Message Boxes. Handling Form Events. Designating the Initial Windows Form. Changing a Windows Form Icon. Assigning Custom Data to a Windows Form. Changing Form Opacity. Supporting Drag and Drop Operations. Creating MDI Forms. Accessing MDI Child Windows. Arranging MDI Child Forms.8. Windows Forms Controls.
Introduction. Displaying Text with a Label Control. Changing Control Properties. Creating a Button and Handling Events. Displaying an Open File Dialog Box. Creating and Attaching Menus to a Windows Form. Creating Context Menus. Displaying System Tray Icons. Opening Web Pages with a LinkLabel Control. Determining Check Box State. Creating Grouped Radio Buttons. Determining the Selected Radio Button. Adding and Removing Items in a ListBox Control. Using a ListView Control. Using ImageLists in a ListView Control. Changing a ListView Mode. Creating ListView Columns. Using the TreeNode Editor. Programmatically Adding Items to a TreeView Control. Using Images in a TreeView. Selecting Items Using the PathSeparator Property. Creating ToolBars. Capturing ToolBar Button Clicks. Adding StatusBar Panels to Display Application State. Adding Tooltips to Controls. Anchoring Controls. Docking Controls. Implementing Control Validation. Visual Inheritance.9. User Controls.
Introduction. Extending Common Controls. Creating Composite Controls. Creating Custom Controls. Using Design-Time Attributes. Changing a Control's Toolbox Icon. Programmatically Adding Controls to the Toolbox. Creating Extender Provider Controls. Creating a UI Type Editor. Utilizing Custom Designers. Extending the Design Time Context Menu. Removing Control Properties Using Metadata Filtering.10. Programming Graphics with GDI+.
Introduction. Obtaining a Graphics Object. Drawing a Rectangle. Drawing a Rectangle with a Hatch Brush. Filling a Rectangle with a Texture Brush. Using Gradient Fills. Drawing Connected Lines and Polygons. Drawing Arc and Pie Shapes. Using Rotation and Translation Transformations. Using Graphics Containers. Forcing a Repaint. Performing Flicker-Free Animation. Enumerating System Fonts. Displaying Text. Enabling Antialiasing. Loading and Displaying Images. Loading and Displaying Animated GIF's. Converting Image File Formats. Printing Documents. Displaying a Print Preview Dialog.11. Localization and Resources.
Introduction. Determining a User's Culture Information. Localizing Windows Forms Controls. Programmatically Changing the Current Culture. Enumerating Culture Types. Using Fallback Resource for Unsupported Regions. Formatting Numbers Correctly Based on Culture. Displaying Culture Aware Date and Time. Formatting Currency for a Specific Culture. Creating and Using Satellite Assemblies. Using ResourceReader to Display an Image Resource. Saving Resource Information Using the ResourceWriter Class.
III. DATA ACCESS.12. File I/O and Serialization.
Introduction. Creating a New File. Verifying the Existence of a File. Opening a File for Reading Using the File Class. Using the FileInfo Class to Display File Information. Copying and Moving a File. Making a File Read Only. Writing to a File. Reading from a File. Appending Data to an Existing File. Improving Performance with a MemoryStream. Monitoring File and Directory Changes. Creating a Directory. Retrieving Directory Information. Enumerating Files and Subdirectories in a Directory. Saving Object State with Serialization. Recreating Objects with Deserialization. Preventing Object Items from Being Serialized. Customizing the Serialization Process.13. XML in .NET.
Introduction. Reading XML Documents with XmlTextReader. Reading with XmlNodeReader. Navigating XML Documents with XPath. Using XmlConvert to Convert XML Data Types. Validating XML Documents with Schemas. Programmatically Generating XML Documents. Controlling XmlTextWriter Formatting. Working with XML Namespaces. Transforming XML Documents with XSLT.14. Database Programming with ADO.NET.
Introduction. Creating a Database Connection. Creating and Filling DataSets. Generating an XML Schema for an Untyped DataSet. Reading Database Records Using SqlDataReader. Creating Forms with the Data Form Wizard. Using Commands and Stored Procedures. Displaying a DataGrid. Databinding Windows Form Controls. Using CommandBuilder to Automatically Generate Commands. Creating Different DataViews of a Table. Adding New Tables to a DataSet. Creating Unique Constraints. Creating ForeignKey Constraints. Inserting New Rows into a DataTable. Modifying Rows in a DataTable. Navigating Tables Using DataRelations. Saving DataSet Information to an XML File. Restoring a DataSet from an XML File. Merging DataSets. Modifying Pooling Behavior for SQL Server Connections. Ensuring Data Integrity Using Transactions.
IV. INTERNET AND NETWORKING.15. Network Programming with Sockets.
Introduction. Creating a Stream-Based Server. Determining Connection Client Information. Resolving an IP Address or Hostname Using DNS. Creating a Stream-Based Client. Creating a Connectionless UDP-Based Server. Creating a Connectionless UDP-Based Client. Controlling Socket Lingering Behavior. Using the WebRequest Class for HTTP Communication. Requesting Web Documents Through a Proxy Server. Creating Asynchronous Web Requests.16. Building ASP.NET Applications.
Introduction. Creating a Simple Web Form. Displaying Server-Side Controls. Handling Web Control Events. Forcing a Post Back from a Web Control Event. Redirecting Users to a Different Web Page. Validating Input Data and Displaying Errors. Databinding Web Controls. Using the DataList Web Control. Using the DataGrid Control. Changing DataGrid Style Information. Creating an Editable DataGrid. Managing Application and Session State. Creating Custom Web Controls. Using Page Output Caching. Writing and Reading Cookies.17. ASP.NET Web Services.
Introduction. Creating an ASP.NET Web Service. Adding Web Service Methods. Providing Web Method Descriptions. Aliasing Web Method Names. Managing Web Service State. Publishing and Registering an ASP.NET Web Service. Consuming Web Services with a Windows Form Application. Consuming Web Services with ASP.NET Applications. Calling Web Methods Asynchronously. Using Transactions in Web Services.18. .NET Remoting.
Introduction. Creating a Remotable Object. Creating Host Applications for Remotable Types. Calling Remote Objects from Client Applications. Performing Client-Side Activation of Remotable Objects. Creating Server-Activated Singleton Objects. Using Remoting Configuration Files. Hosting Remotable Types with IIS. Using Channels and Formatters. Controlling Lifetime Leases. Performing Asynchronous Remoting Calls. Creating Proxies for Message Interception. Creating Custom Channel Sinks for Logging.
V. DEPLOYMENT AND SECURITY.19. Assemblies.
Introduction. Setting Informational Assembly Attributes. Setting the Assembly Version. Viewing Assembly Contents with ILDasm. Creating a Multifile Assembly. Creating a Strong Name Assembly. Delay Signing an Assembly. Creating a Shared Assembly. Securing Satellite Assemblies. Explicitly Loading an Assembly Programmatically. Reading Assembly Identity Programmatically. Identifying the File or URL from Which an Assembly Was Loaded. Loading an Assembly into a New Application Domain.20. Setup and Deployment Projects.
Introduction. Creating setup.exe-Based Installations. Creating a Windows Setup Project Without Using the Wizard. Adding a Shortcut on the User's Desktop. Customizing the Appearance of the Setup Dialogs. Adding User-Interface Dialogs. Setting Launch Conditions on the Installation. Conditionally Installing Files. Creating a Custom Executable Action. Creating Custom Actions as Classes. Installing Assemblies into the Global Assembly Cache.21. Securing Code.
Introduction. Requesting Permissions for an Assembly Using Declarative Security. Requesting Permissions for a Class or Method Using Declarative Security. Requesting Permissions Using Imperative Security Requests. Viewing Security Policy Information. Creating Code Groups. Creating New Permission Sets. Determining Whether the Current User Is an Administrator. Creating Login Pages with Web Forms Authentication. Unsafe Code Using Pointers. Calling Native Unmanaged Code Using PInvoke.
VI. ADVANCED TOPICS.22. Threading and Synchronization.
Introduction. Creating and Starting Threads. Pausing and Resuming a Thread. Aborting the Execution of a Thread. Changing the Priority of a Running Thread. Using the ThreadPool to Perform Background Tasks. Creating an Application Timer. Synchronizing Variable Access Using the Monitor. Using Events to Synchronize Threads. Using Mutexes to Synchronize Multiple Objects, Avoiding Deadlocks. Implementing Interprocess Communication Using a Mutex. Synchronizing Resource Access Using Reader/Writer Locks. Getting and Setting Thread Data Using Thread Local Storage.23. Reflection.
Introduction. Viewing Assembly Information. Examining Module Information. Examining Constructor Information. Examining Methods Within a Type. Displaying Event Information. Displaying Property Information. Searching Assembly Information Using Filtering. Searching Assemblies Using Custom Search Techniques. Creating Dynamic Assemblies. Performing Dynamic Invocation. Creating a Plug-In Architecture.24. COM Interoperability.
Introduction. Creating an ATL-Based COM Component. Using COM Objects in .NET. Automatically Generating an Interop Assembly. Using ActiveX Controls in a Windows Form. Viewing the RCW Using ILDasm.exe. Handling HRESULT Errors. Using .NET Objects in COM. Viewing an Exported .NET Type Library. Controlling Managed Thread Apartment States.25. Custom Attributes.
Introduction. Creating a Custom Attribute Class Definition. Declaring Targets for Custom Attributes. Allowing Custom Attributes to Be Applied Multiple Times. Defining the Inheritance Model of Custom Attributes. Adding Optional Properties to Custom Attributes. Displaying Custom Attribute Information Using Reflection. Displaying Assembly Custom Attribute Information Using Reflection. Displaying Properties of an Applied Attribute at Runtime.26. Smart Device Extensions.
Introduction. Understanding the Differences Between the Compact and .NET Frameworks. Creating a Smart Device Solution. Creating and Displaying Windows Forms. Manipulating the Soft Input Panel. Using the MessageWindow Class. Creating an IrDA Client. Creating an IrDA Server. Building CAB Files for Application Distribution. Deploying Mobile Applications Using ActiveSync. Creating Mobile ASP.NET Pages. Using the Mobile ASP.NET ObjectList Control. Querying Mobile Device Capabilities. Changing Mobile Web Form Output Using the DeviceSpecific Control. Creating a SqlServerCE Database. Using a SQL Server CE Database.
VII. APPENDIXES.Appendix A. Visual Studio .NET IDE.
Source Editing. Tool Windows. Visual Studio .NET Toolbars.Appendix B. .NET Debugging .Reference.
Working with Breakpoints. Debugging an Application.Index.