C# Cookbook
Home > Computing and Information Technology > Computer programming / software engineering > Programming and scripting languages: general > C# Cookbook
C# Cookbook

C# Cookbook


     0     
5
4
3
2
1



Out of Stock


Notify me when this book is in stock
X
About the Book

With "C# Cookbook, 2nd Edition", you'll be able to learn and improve your mastery of both the C# language and the .NET platform. This updated bestseller has been completely revised to account for C# 2.0, the latest version of this popular object-oriented programming language. It also includes more than 100 new code solutions (over 300 overall) to common problems and tasks that you're sure to face as a C# programmer. Nearly every solution, or "recipe," contains a complete, documented code sample showing you how to solve the specific problem, as well as a detailed discussion of how and why the underling technology works. This question-solution-discussion format is a proven teaching method, as any fan of O'Reilly's "Cookbook" series can attest to. In fact, no other source offers a learn-as-you-go format quite like this. "C# Cookbook, 2nd Edition" is organized into 20 chapters, each of which focuses on a particular topic in creating C# solutions. Here's just a taste of what's covered: numeric data types; strings and characters; classes and structures; generics; exception handling; delegates, events, and anonymous methods; filesystem interactions; web site access; XML usage (including XPath and XSLT); networking; threading; and unsafe code. Best of all, you don't have to be an experienced C# or .NET developer to use "C# Cookbook, 2nd Edition". You just have to be someone who wants to solve a problem now, without having to learn all the related theory first.

Table of Contents:
Preface 1. Numbers and Enumerations 1.1 Determining Approximate Equality Between a Fraction and Floating-Point Value 1.2 Converting Degrees to Radians 1.3 Converting Radians to Degrees 1.4 Using the Bitwise Complement Operator with Various Data Types 1.5 Testing for an Even or Odd Value 1.6 Obtaining the High Word or Low Word of a Number 1.7 Converting a Number in Another Base to Base10 1.8 Determining Whether a String Is a Valid Number 1.9 Rounding a Floating-Point Value 1.10 Choosing a Rounding Algorithm 1.11 Converting Celsius to Fahrenheit 1.12 Converting Fahrenheit to Celsius 1.13 Safely Performing a Narrowing Numeric Cast 1.14 Finding the Length of Any Three Sides of a Right Triangle 1.15 Finding the Angles of a Right Triangle 1.16 Displaying an Enumeration Value as a String 1.17 Converting Plain Text to an Equivalent Enumeration Value 1.18 Testing for a Valid Enumeration Value 1.19 Testing for a Valid Enumeration of Flags 1.20 Using Enumerated Members in a Bit Mask 1.21 Determining if One or More Enumeration Flags Are Set 1.22 Determining the Integral Part of a Decimal or Double 2. Strings and Characters 2.1 Determining the Kind of Character a char Contains 2.2 Determining Whether a Character Is Within a Specified Range 2.3 Controlling Case Sensitivity When Comparing Two Characters 2.4 Finding All Occurrences of a Character Within a String 2.5 Finding the Location of All Occurrences of a String Within Another String 2.6 Implementing a Poor Man's Tokenizer to Deconstruct a String 2.7 Controlling Case Sensitivity When Comparing Two Strings 2.8 Comparing a String to the Beginning or End of a Second String 2.9 Inserting Text into a String 2.10 Removing or Replacing Characters Within a String 2.11 Encoding Binary Data as Base64 2.12 Decoding a Base64-Encoded Binary 2.13 Converting a String Returned as a Byte[ ] Back into a String 2.14 Passing a String to a Method That Accepts only a Byte[ ] 2.15 Converting Strings to Other Types 2.16 Formatting Data in Strings 2.17 Creating a Delimited String 2.18 Extracting Items from a Delimited String 2.19 Setting the Maximum Number of Characters a StringBuilder Can Contain 2.20 Iterating over Each Character in a String 2.21 Improving String Comparison Performance 2.22 Improving StringBuilder Performance 2.23 Pruning Characters from the Head and/or Tail of a String 2.24 Testing a String for Null or Empty 2.25 Appending a Line 2.26 Encoding Chunks of Data 3. Classes and Structures 3.1 Creating Union-Type Structures 3.2 Allowing a Type to Represent Itself as a String 3.3 Converting a String Representation of an Object into an Actual Object 3.4 Implementing Polymorphism with Abstract Base Classes 3.5 Making a Type Sortable 3.6 Making a Type Searchable 3.7 Indirectly Overloading the +=, -=, /=, and *= Operators 3.8 Indirectly Overloading the &&, ||, and ?: Operators 3.9 Turning Bits On or Off 3.10 Making Error-Free Expressions 3.11 Minimizing (Reducing) Your Boolean Logic 3.12 Converting Between Simple Types in a Language-Agnostic Manner 3.13 Determining When to Use the Cast Operator, the as Operator, or the is Operator 3.14 Casting with the as Operator 3.15 Determining a Variable's Type with the is Operator 3.16 Implementing Polymorphism with Interfaces 3.17 Calling the Same Method on Multiple Object Types 3.18 Adding a Notification Callback Using an Interface 3.19 Using Multiple Entry Points to Version an Application 3.20 Preventing the Creation of an Only Partially Initialized Object 3.21 Returning Multiple Items from a Method 3.22 Parsing Command-Line Parameters 3.23 Retrofitting a Class to Interoperate with COM 3.24 Initializing a Constant Field at Runtime 3.25 Writing Code That Is Compatible with the Widest Range of Managed Languages 3.26 Building Cloneable Classes 3.27 Assuring an Object's Disposal 3.28 Releasing a COM Object Through Managed Code 3.29 Creating an Object Cache 3.30 Rolling Back Object Changes 3.31 Disposing of Unmanaged Resources 3.32 Determining Where Boxing and Unboxing Occur 4. Generics 4.1 Deciding When and Where to Use Generics 4.2 Understanding Generic Types 4.3 Getting the Type of a Generic Type 4.4 Replacing the ArrayList with Its Generic Counterpart 4.5 Replacing the Stack and Queue with Their Generic Counterparts 4.6 Implementing a Linked List 4.7 Creating a Value Type That Can be Initialized to Null 4.8 Reversing the Contents of a Sorted List 4.9 Making Read-Only Collections the Generic Way 4.10 Replacing the Hashtable with Its Generic Counterpart 4.11 Using foreach with Generic Dictionary Types 4.12 Constraining Type Arguments 4.13 Initializing Generic Variables to Their Default Values 5. Collections 5.1 Swapping Two Elements in an Array 5.2 Reversing an Array Quickly 5.3 Reversing a Two-Dimensional Array 5.4 Reversing a Jagged Array 5.5 Writing a More Flexible StackTrace Class 5.6 Determining the Number of Times an Item Appears in a List 5.7 Retrieving All Instances of a Specific Item in a List 5.8 Inserting and Removing Items from an Array 5.9 Keeping Your List Sorted 5.10 Sorting a Dictionary's Keys and/or Values 5.11 Creating a Dictionary with Max and Min Value Boundaries 5.12 Displaying an Array's Data as a Delimited String 5.13 Storing Snapshots of Lists in an Array 5.14 Persisting a Collection Between Application Sessions 5.15 Testing Every Element in an Array or List 5.16 Performing an Action on Each Element in an Array or List 5.17 Creating a Read-Only Array or List 6. Iterators and Partial Types 6.1 Implementing Nested foreach Functionality in a Class 6.2 Creating Custom Enumerators 6.3 Creating an Iterator on a Generic Type 6.4 Creating an Iterator on a Non-generic Type 6.5 Creating Iterators That Accept Parameters 6.6 Adding Multiple Iterators on a Single Type 6.7 Implementing Iterators as Overloaded Operators 6.8 Forcing an Iterator to Stop Iterating 6.9 Dealing with Finally Blocks and Iterators 6.10 Organizing Your Interface Implementations 6.11 Generating Code That Is No Longer in Your Main Code Paths 7. Exception Handling 7.1 Verifying Critical Parameters 7.2 Knowing When to Catch and Rethrow Exceptions 7.3 Identifying Exceptions and Their Usage 7.4 Handling Derived Exceptions Individually 7.5 Assuring Exceptions Are Not Lost When Using Finally Blocks 7.6 Handling Exceptions Thrown from Methods Invoked via Reflection 7.7 Debugging Problems When Loading an Assembly 7.8 Mapping Back and Forth Between Managed Exceptions and HRESULTs 7.9 Handling User-Defined HRESULTs 7.10 Preventing Unhandled Exceptions 7.11 Getting Exception Information 7.12 Getting to the Root of a Problem Quickly 7.13 Creating a New Exception Type 7.14 Obtaining a Stack Trace 7.15 Breaking on a First-Chance Exception 7.16 Preventing the Nefarious TypeInitializationException 7.17 Handling Exceptions Thrown from an Asynchronous Delegate 7.18 Giving Exceptions the Extra Info They Need with Exception.Data 7.19 Looking at Exceptions in a New Way Using Visualizers 7.20 Dealing with Unhandled Exceptions in WinForms Applications 8. Diagnostics 8.1 Controlling Tracing Output in Production Code 8.2 Providing Fine-Grained Control over Debugging/Tracing Output 8.3 Creating Your Own Custom Switch Class 8.4 Compiling Blocks of Code Conditionally 8.5 Determining Whether a Process Has Stopped Responding 8.6 Using Event Logs in Your Application 8.7 Changing the Maximum Size of a Custom Event Log 8.8 Searching Event Log Entries 8.9 Watching the Event Log for a Specific Entry 8.10 Finding All Sources Belonging to a Specific Event Log 8.11 Implementing a Simple Performance Counter 8.12 Implementing Performance Counters That Require a Base Counter 8.13 Enabling and Disabling Complex Tracing Code 8.14 Capturing Standard Output for a Process 8.15 Creating Custom Debugging Displays for Your Classes 8.16 Determining Current AppDomain Settings Information 8.17 Boosting the Priority of a Process Programmatically 8.18 Looking at Your Runtime Environment and Seeing What You Can Do About It 9. Delegates, Events, and Anonymous Methods 9.1 Controlling When and If a Delegate Fires Within a Multicast Delegate 9.2 Obtaining Return Values from Each Delegate in a Multicast Delegate 9.3 Handling Exceptions Individually for Each Delegate in a ulticast Delegate 9.4 Converting Delegate Invocation from Synchronous to Asynchronous 9.5 Wrapping Sealed Classes to Add Events 9.6 Passing Specialized Parameters to and from an Event 9.7 An Advanced Interface Search Mechanism 9.8 An Advanced Member Search Mechanism 9.9 Observing Additions and Modifications to a Hashtable 9.10 Using the Windows Keyboard Hook 9.11 Tracking and Responding to the Mouse 9.12 Using Anonymous Methods 9.13 Set Up Event Handlers Without the Mess 9.14 Using Different Parameter Modifiers in Anonymous Methods 9.15 Using Closures in C# 9.16 Performing Multiple Operations on a List Using Functors 10. Regular Expressions 10.1 Enumerating Matches 10.2 Extracting Groups from a MatchCollection 10.3 Verifying the Syntax of a Regular Expression 10.4 Quickly Finding Only the Last Match in a String 10.5 Replacing Characters or Words in a String 10.6 Augmenting the Basic String Replacement Function 10.7 Implementing a Better Tokenizer 10.8 Compiling Regular Expressions 10.9 Counting Lines of Text 10.10 Returning the Entire Line in Which a Match Is Found 10.11 Finding a Particular Occurrence of a Match 10.12 Using Common Patterns 10.13 Documenting Your Regular Expressions 10.14 Using Built-in Regular Expressions to Parse ASP.NET Pages 11. Data Structures and Algorithms 11.1 Creating a Hash Code for a Data Type 11.2 Creating a Priority Queue 11.3 Creating a Double Queue 11.4 Determining Where Characters or Strings Do Not Balance 11.5 Creating a One-to-Many Map (MultiMap) 11.6 Creating a Binary Tree 11.7 Creating an n-ary Tree 11.8 Creating a Set Object 12. Filesystem I/O 12.1 Creating, Copying, Moving, or Deleting a File 12.2 Manipulating File Attributes 12.3 Renaming a File 12.4 Determining Whether a File Exists 12.5 Choosing a Method of Opening a File or Stream for Reading and/or Writing 12.6 Accessing Part of a File Randomly 12.7 Outputting a Platform-Independent EOL Character 12.8 Creating, Writing to, and Reading from a File 12.9 Determining Whether a Directory Exists 12.10 Creating, Copying, Moving, or Deleting a Directory 12.11 Manipulating Directory Attributes 12.12 Renaming a Directory 12.13 Searching for Directories or Files Using Wildcards 12.14 Obtaining the Directory Tree 12.15 Parsing a Path 12.16 Parsing Paths in Environment Variables 12.17 Verifying a Path 12.18 Using a Temporary File in Your Application 12.19 Opening a File Stream with Just a File Handle 12.20 Writing to Multiple Output Files at One Time 12.21 Launching and Interacting with Console Utilities 12.22 Locking Subsections of a File 12.23 Watching the Filesystem for Specific Changes to One or More Files or Directories 12.24 Waiting for an Action to Occur in the Filesystem 12.25 Comparing Version Information of Two Executable Modules 12.26 Querying Information for All Drives on a System 12.27 Encrypting/Decrypting an Existing File 12.28 Compressing and Decompressing Your Files 13. Reflection 13.1 Listing Referenced Assemblies 13.2 Listing Exported Types 13.3 Finding Overridden Methods 13.4 Finding Members in an Assembly 13.5 Finding Members Within an Interface 13.6 Determining and Obtaining Nested Types Within an Assembly 13.7 Displaying the Inheritance Hierarchy for a Type 13.8 Finding the Subclasses of a Type 13.9 Finding All Serializable Types Within an Assembly 13.10 Filtering Output When Obtaining Members 13.11 Dynamically Invoking Members 13.12 Providing Guidance to Obfuscators 13.13 Determining if a Type or Method Is Generic 13.14 Reading Manifest Resources Programmatically 13.15 Accessing Local Variable Information 13.16 Creating a Generic Type 14. Web 14.1 Converting an IP Address to a Hostname 14.2 Converting a Hostname to an IP Address 14.3 Parsing a URI 14.4 Forming and Validating an Absolute URI 14.5 Handling Web Server Errors 14.6 Communicating with a Web Server 14.7 Going Through a Proxy 14.8 Obtaining the HTML from a URL 14.9 Using the New Web Browser Control 14.10 Tying Database Tables to the Cache 14.11 Caching Data with Multiple Dependencies 14.12 Prebuilding an ASP.NET Web Site Programmatically 14.13 Escaping and Unescaping Data for the Web 14.14 Using the UriBuilder Class 14.15 Inspect and Change Your Web Application Configuration 14.16 Working with HTML 14.17 Using Cached Results When Working with HTTP for Faster Performance 14.18 Checking out a Web Server's Custom Error Pages 14.19 Determining the Application Mappings for 18. Threading and Synchronization 18.1 Creating Per-Thread Static Fields 18.2 Providing Thread-Safe Access to Class Members 18.3 Preventing Silent Thread Termination 18.4 Polling an Asynchronous Delegate 18.5 Timing Out an Asynchronous Delegate 18.6 Being Notified of the Completion of an Asynchronous Delegate 18.7 Determining Whether a Request for a Pooled Thread Will be Queued 18.8 Configuring a Timer 18.9 Storing Thread-Specific Data Privately 18.10 Granting Multiple Access to Resources with a Semaphore 18.11 Synchronizing Multiple Processes with the Mutex 18.12 Using Events to Make Threads Cooperate 18.13 Get the Naming Rights for Your Events 18.14 Performing Atomic Operations Among Threads 19. Unsafe Code 19.1 Controlling Changes to Pointers Passed to Methods 19.2 Comparing Pointers 19.3 Navigating Arrays 19.4 Manipulating a Pointer to a Fixed Array 19.5 Returning a Pointer to a Particular Element in an Array 19.6 Creating and Using an Array of Pointers 19.7 Switching Unknown Pointer Types 19.8 Converting a String to a char* 19.9 Declaring a Fixed-Size Structure with an Embedded Array 20. Toolbox 20.1 Dealing with Operating System Shutdown, Power Management, or User Session Changes 20.2 Controlling a Service 20.3 List What Processes an Assembly Is Loaded In 20.4 Using Message Queues on a Local Workstation 20.5 Finding the Path to the Current Framework Version 20.6 Determining the Versions of an Assembly That Are Registered in the Global Assembly Cache (GAC) 20.7 Getting the Windows Directory 20.8 Capturing Output from the Standard Output Stream 20.9 Running Code in Its Own AppDomain 20.10 Determining the Operating System and Service Pack Version of the Current Operating System Index

About the Author :
Jay Hilyard has been developing applications for the Windows platform for over 10 years and is currently a .NET enthusiast. Jay has published an article in MSDN Magazine on Profiling and Garbage Collection and he currently works on the BoundsChecker team at the Compuware NuMega Lab in Nashua, NH. When not immersed in .NET, Jay spends his time with his family and rooting for the Patriots. Stephen Teilhet earned a degree in electrical engineering but soon afterwards began writing software for the Windows platform. For the last eight years, he has worked for several consulting firms on a wide range of projects, specializing in Visual Basic, Visual C++, MTS, COM, MSMQ, and SQL Server. Stephen currently works for Compuware Numega Labs in Nashua, New Hampshire, where he is immersed in the Microsoft .NET technologies.


Best Sellers


Product Details
  • ISBN-13: 9780596100636
  • Publisher: O'Reilly Media
  • Publisher Imprint: O'Reilly Media
  • Edition: Revised edition
  • Language: English
  • Width: 178 mm
  • ISBN-10: 0596100639
  • Publisher Date: 07 Mar 2006
  • Binding: Paperback
  • Height: 232 mm
  • Returnable: N


Similar Products

Add Photo
Add Photo

Customer Reviews

REVIEWS      0     
Click Here To Be The First to Review this Product
C# Cookbook
O'Reilly Media -
C# Cookbook
Writing guidlines
We want to publish your review, so please:
  • keep your review on the product. Review's that defame author's character will be rejected.
  • Keep your review focused on the product.
  • Avoid writing about customer service. contact us instead if you have issue requiring immediate attention.
  • Refrain from mentioning competitors or the specific price you paid for the product.
  • Do not include any personally identifiable information, such as full names.

C# Cookbook

Required fields are marked with *

Review Title*
Review
    Add Photo Add up to 6 photos
    Would you recommend this product to a friend?
    Tag this Book Read more
    Does your review contain spoilers?
    What type of reader best describes you?
    I agree to the terms & conditions
    You may receive emails regarding this submission. Any emails will include the ability to opt-out of future communications.

    CUSTOMER RATINGS AND REVIEWS AND QUESTIONS AND ANSWERS TERMS OF USE

    These Terms of Use govern your conduct associated with the Customer Ratings and Reviews and/or Questions and Answers service offered by Bookswagon (the "CRR Service").


    By submitting any content to Bookswagon, you guarantee that:
    • You are the sole author and owner of the intellectual property rights in the content;
    • All "moral rights" that you may have in such content have been voluntarily waived by you;
    • All content that you post is accurate;
    • You are at least 13 years old;
    • Use of the content you supply does not violate these Terms of Use and will not cause injury to any person or entity.
    You further agree that you may not submit any content:
    • That is known by you to be false, inaccurate or misleading;
    • That infringes any third party's copyright, patent, trademark, trade secret or other proprietary rights or rights of publicity or privacy;
    • That violates any law, statute, ordinance or regulation (including, but not limited to, those governing, consumer protection, unfair competition, anti-discrimination or false advertising);
    • That is, or may reasonably be considered to be, defamatory, libelous, hateful, racially or religiously biased or offensive, unlawfully threatening or unlawfully harassing to any individual, partnership or corporation;
    • For which you were compensated or granted any consideration by any unapproved third party;
    • That includes any information that references other websites, addresses, email addresses, contact information or phone numbers;
    • That contains any computer viruses, worms or other potentially damaging computer programs or files.
    You agree to indemnify and hold Bookswagon (and its officers, directors, agents, subsidiaries, joint ventures, employees and third-party service providers, including but not limited to Bazaarvoice, Inc.), harmless from all claims, demands, and damages (actual and consequential) of every kind and nature, known and unknown including reasonable attorneys' fees, arising out of a breach of your representations and warranties set forth above, or your violation of any law or the rights of a third party.


    For any content that you submit, you grant Bookswagon a perpetual, irrevocable, royalty-free, transferable right and license to use, copy, modify, delete in its entirety, adapt, publish, translate, create derivative works from and/or sell, transfer, and/or distribute such content and/or incorporate such content into any form, medium or technology throughout the world without compensation to you. Additionally,  Bookswagon may transfer or share any personal information that you submit with its third-party service providers, including but not limited to Bazaarvoice, Inc. in accordance with  Privacy Policy


    All content that you submit may be used at Bookswagon's sole discretion. Bookswagon reserves the right to change, condense, withhold publication, remove or delete any content on Bookswagon's website that Bookswagon deems, in its sole discretion, to violate the content guidelines or any other provision of these Terms of Use.  Bookswagon does not guarantee that you will have any recourse through Bookswagon to edit or delete any content you have submitted. Ratings and written comments are generally posted within two to four business days. However, Bookswagon reserves the right to remove or to refuse to post any submission to the extent authorized by law. You acknowledge that you, not Bookswagon, are responsible for the contents of your submission. None of the content that you submit shall be subject to any obligation of confidence on the part of Bookswagon, its agents, subsidiaries, affiliates, partners or third party service providers (including but not limited to Bazaarvoice, Inc.)and their respective directors, officers and employees.

    Accept

    New Arrivals


    Inspired by your browsing history


    Your review has been submitted!

    You've already reviewed this product!