買這商品的人也買了...
-
$680$537 -
$580$458 -
$880$695 -
$860$568 -
$650$429 -
$780$741 -
$780CMMI: Guidelines for Process Integration and Product Improvement (Harcover)
-
$590$466 -
$690$538 -
$650$618 -
$720$569 -
$880$792 -
$750$638 -
$560$476 -
$550$468 -
$490$417 -
$880$695 -
$850$723 -
$480$379 -
$750$593 -
$780$616 -
$490$382 -
$690$587 -
$620$490 -
$480$408
相關主題
商品描述
The C# Cookbook offers a definitive collection of solutions and examples for this new programming language. Recipes range from simple tasks to the more complex, and are organized with respect to the types of problems you'll need to solve as you progress in your experience as a C# programmer. Nearly every recipe contains a complete, documented code sample showing you how to solve the specific problem, as well as a discussion of how the underlying technology works and a discussion of alternatives, limitations, and other considerations where appropriate.
The recipes in the C# Cookbook are organized into seventeen chapters, each of which focuses on a particular topic in creating C# solutions. Among the topics covered, you'll find:
- Numeric data types in C#
- Strings and characters
- Classes and structures
- Exception handling
- Delegates and events
- Regular expressions
- Data structures and algorithms
- Networking
- Security
- Unsafe Code
You don't need to be an experienced C# or .NET developer to use this
book. The C# Cookbook is designed for users of all levels with recipes
targeted at the real-world developer who needs to solve problems now, not learn
lots of theory first. With this guide, all developers will be able to learn and
improve their mastery of both the language and the .NET Framework Class
Libraries.
Table of Contents
Preface
1. Numbers
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 Test for an Even or Odd Value
1.6 Obtaining the Most- or Least-Significant Bits 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 Different Rounding Algorithms
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 Triangle2. Strings and Characters
2.1 Determining the Kind of Character
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 WithinAnother String
2.6 The Poor Man's Tokenizer
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 Their Equivalent Value Type
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 String 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 String3. 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 Polymorphism via Concrete or 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 Improving the Performance of a Structure's Equals Method
3.10 Turning Bits On or Off
3.11 Making Error-Free Expressions
3.12 Minimizing (Reducing) Your Boolean Logic
3.13 Converting Between Simple Types in a Language Agnostic Manner
3.14 Determining Whether to Use the Cast Operator, the as Operator, or the is Operator
3.15 Casting with the as Operator
3.16 Determining a Variable's Type with the is Operator
3.17 Polymorphism via Interfaces
3.18 Calling the Same Method on Multiple Object Types
3.19 Adding a Notification Callback Using an Interface
3.20 Using Multiple Entry Points to Version an Application
3.21 Preventing the Creation of an Only Partially Initialized Object
3.22 Returning Multiple Items from a Method
3.23 Parsing Command-Line Parameters
3.24 Retrofitting a Class to Interoperate with COM
3.25 Initializing a Constant Field at Runtime
3.26 Writing Code that Is Compatible with the Widest Rangeof Managed Languages
3.27 Implementing Nested foreach Functionality in a Class
3.28 Building Cloneable Classes
3.29 Assuring an Object's Disposal
3.30 Releasing a COM Object Through Managed Code
3.31 Creating an Object Cache
3.32 The Single Instance Object
3.33 Choosing a Serializer
3.34 Creating Custom Enumerators
3.35 Rolling Back Object Changes
3.36 Disposing of Unmanaged Resources
3.37 Determining Where Boxing and Unboxing Occur4. Enumerations
4.1 Displaying an Enumeration Value as a String
4.2 Converting Plain Text to an Equivalent Enumeration Value
4.3 Testing for a Valid Enumeration Value
4.4 Testing for a Valid Enumeration of Flags
4.5 Using Enumerated Members in a Bitmask
4.6 Determining Whether One or More Enumeration Flags Are Set5. Exception Handling
5.1 Verifying Critical Parameters
5.2 Indicating Where Exceptions Originate
5.3 Choosing when to Throw a Particular Exception
5.4 Handling Derived Exceptions Individually
5.5 Assuring Exceptions are Not Lost when Using Finally Blocks
5.6 Handling Exceptions Thrown from Methods Invoked via Reflection
5.7 Debugging Problems when Loading an Assembly
5.8 HRESULT-Exception Mapping
5.9 Handling User-Defined HRESULTs
5.10 Preventing Unhandled Exceptions
5.11 Displaying Exception Information
5.12 Getting to the Root of a Problem Quickly
5.13 Creating a New Exception Type
5.14 Obtaining a Stack Trace
5.15 Breaking on a First Chance Exception
5.16 Preventing the Nefarious TypeInitializationException
5.17 Handling Exceptions Thrown from an Asynchronous Delegate6. Diagnostics
6.1 Controlling Tracing Output in Production Code
6.2 Providing Fine-Grained Control Over Debugging/Tracing Output
6.3 Creating Your Own Custom Switch Class
6.4 A Custom Trace Class that Outputs Information in an XML Format
6.5 Conditionally Compiling Blocks of Code
6.6 Determining Whether a Process Has Stopped Responding
6.7 Using One or More Event Logs in Your Application
6.8 Changing the Maximum Size of a Custom Event Log
6.9 Searching Event Log Entries
6.10 Watching the Event Log for a Specific Entry
6.11 Finding All Sources Belonging to a Specific Event Log
6.12 Implementing a Simple Performance Counter
6.13 Implementing Performance Counters that Require a Base Counter
6.14 Enable/Disable Complex Tracing Code7. Delegates and Events
7.1 Controlling when and if a Delegate Fires Within a Multicast Delegate
7.2 Obtaining Return Values from Each Delegate in a Multicast Delegate
7.3 Handling Exceptions Individually for Each Delegate in a Multicast Delegate
7.4 Converting a Synchronous Delegate to an Asynchronous Delegate
7.5 Adding Events to a Sealed Class
7.6 Passing Specialized Parameters to and from an Event
7.7 An Advanced Interface Search Mechanism
7.8 An Advanced Member Search Mechanism
7.9 Observing Additions and Modifications to a Hashtable
7.10 Using the Windows Keyboard Hook
7.11 Using Windows Hooks to Manipulate the Mouse8. Regular Expressions
8.1 Enumerating Matches
8.2 Extracting Groups from a MatchCollection
8.3 Verifying the Syntax of a Regular Expression
8.4 Quickly Finding Only the Last Match in a String
8.5 Replacing Characters or Words in a String
8.6 Augmenting the Basic String Replacement Function
8.7 A Better Tokenizer
8.8 Compiling Regular Expressions
8.9 Counting Lines of Text
8.10 Returning the Entire Line in Which a Match Is Found
8.11 Finding a Particular Occurrence of a Match
8.12 Using Common Patterns
8.13 Documenting Your Regular Expressions9. Collections
9.1 Swapping Two Elements in an Array
9.2 Quickly Reversing an Array
9.3 Reversing a Two-Dimensional Array
9.4 Reversing a Jagged Array
9.5 A More Flexible StackTrace Class
9.6 Determining the Number of Times an Item Appears in an ArrayList
9.7 Retrieving All Instances of a Specific Item in an ArrayList
9.8 Inserting and Removing Items from an Array
9.9 Keeping Your ArrayList Sorted
9.10 Sorting a Hashtable's Keys and/or Values
9.11 Creating a Hashtable with Max and Min Size Boundaries
9.12 Creating a Hashtable with Max and Min Value Boundaries
9.13 Displaying an Array's Data as a Delimited String
9.14 Storing Snapshots of Lists in an Array
9.15 Creating a Strongly Typed Collection
9.16 Persisting a Collection Between Application Sessions10. Data Structures and Algorithms
10.1 Creating a Hash Code for a Data Type
10.2 Creating a Priority Queue
10.3 Creating a More Versatile Queue
10.4 Determining Where Characters or Strings Do Not Balance
10.5 Creating a One-to-Many Map (MultiMap)
10.6 Creating a Binary Tree
10.7 Creating an n-ary Tree
10.8 Creating a Set Object11. Filesystem I/O
11.1 Creating, Copying, Moving, and Deleting a File
11.2 Manipulating File Attributes
11.3 Renaming a File
11.4 Determining Whether a File Exists
11.5 Choosing a Method of Opening a File or Stream for Reading and/or Writing
11.6 Randomly Accessing Part of a File
11.7 Outputting a Platform-Independent EOL Character
11.8 Create, Write to, and Read from a File
11.9 Determining Whether a Directory Exists
11.10 Creating, Moving, and Deleting a Directory
11.11 Manipulating Directory Attributes
11.12 Renaming a Directory
11.13 Searching for Directories or Files Using Wildcards
11.14 Obtaining the Directory Tree
11.15 Parsing a Path
11.16 Parsing Paths in Environment Variables
11.17 Verifying a Path
11.18 Using a Temporary File in Your Application
11.19 Opening a File Stream with just a File Handle
11.20 Write to Multiple Output Files at One Time
11.21 Launching and Interacting with Console Utilities
11.22 Locking Subsections of a File
11.23 Watching the Filesystem for Specific Changes to One or MoreFiles or Directories
11.24 Waiting for an Action to Occur in the Filesystem
11.25 Comparing Version Information of Two Executable Modules12. Reflection
12.1 Listing Imported Assemblies
12.2 Listing Exported Types
12.3 Finding Overridden Methods
12.4 Finding Members in an Assembly
12.5 Finding Members Within an Interface
12.6 Obtaining Types Nested Within a Type
12.7 Displaying the Inheritance Hierarchy for a Type
12.8 Finding the Subclasses of a Type
12.9 Finding All Serializable Types Within an Assembly
12.10 Controlling Additions to an ArrayList Through Attributes
12.11 Filtering Output when Obtaining Members
12.12 Dynamically Invoking Members13. Networking
13.1 Converting an IP Address to a Hostname
13.2 Converting a Hostname to an IP Address
13.3 Parsing a URI
13.4 Forming an Absolute URI
13.5 Handling Web Server Errors
13.6 Communicating with a Web Server
13.7 Going Through a Proxy
13.8 Obtaining the HTML from a URL
13.9 Writing a TCP Server
13.10 Writing a TCP Client
13.11 Simulating Form Execution
13.12 Downloading Data from a Server
13.13 Using Named Pipes to Communicate14. Security
14.1 Controlling Access to Types in a Local Assembly
14.2 Encrypting/Decrypting a String
14.3 Encrypting and Decrypting a File
14.4 Cleaning Up Cryptography Information
14.5 Verifying that a String Is Uncorrupted During Transmission
14.6 Wrapping a String Hash for Ease of Use
14.7 A Better Random Number Generator
14.8 Securely Storing Data
14.9 Making a Security Assert Safe
14.10 Preventing Malicious Modifications to an Assembly
14.11 Verifying that an Assembly Has Been Granted Specific Permissions
14.12 Minimizing the Attack Surface of an Assembly15. Threading
15.1 Creating Per-Thread Static Fields
15.2 Providing Thread Safe Access to Class Members
15.3 Preventing Silent Thread Termination
15.4 Polling an Asynchronous Delegate
15.5 Timing Out an Asynchronous Delegate
15.6 Being Notified of the Completion of an Asynchronous Delegate
15.7 Waiting for Worker Thread Completion
15.8 Synchronizing the Reading and Writing of a Resource Efficiently
15.9 Determining Whether a Request for a Pooled ThreadWill Be Queued
15.10 Waiting for All Threads in the Thread Pool to Finish
15.11 Configuring a Timer
15.12 Storing Thread-Specific Data Privately16. Unsafe Code
16.1 Controlling Changes to Pointers Passed to Methods
16.2 Comparing Pointers
16.3 Navigating Arrays
16.4 Manipulating a Pointer to a Fixed Array
16.5 Returning a Pointer to a Particular Element in an Array
16.6 Creating and Using an Array of Pointers
16.7 Creating and Using an Array of Pointers to Unknown Types
16.8 Switching Unknown Pointer Types
16.9 Breaking Up Larger Numbers into Their Equivalent Byte Array Representation
16.10 Converting Pointers to a Byte[], SByte[], or Char[] to a String17. XML
17.1 Reading and Accessing XML Data in Document Order
17.2 Reading XML on the Web
17.3 Querying the Contents of an XML Document
17.4 Validating XML
17.5 Creating an XML Document Programmatically
17.6 Detecting Changes to an XML Document
17.7 Handling Invalid Characters in an XML String
17.8 Transforming XML to HTML
17.9 Tearing Apart an XML Document
17.10 Putting Together an XML DocumentIndex
商品描述(中文翻譯)
易於學習和使用的 C# 語言,針對的是曾經使用過 C 類語言(如 C、C++ 或 Java)的 Microsoft .NET 平台開發者。對於新開發者來說,有大量優秀的教程和文檔可供參考,例如 O'Reilly 的《Learning C#》或《Programming C#》。但當你需要針對日常問題的實用解答時,教程可能無法滿足需求。《C# Cookbook》直接針對問題核心,提供專為在 .NET 平台上工作的開發者收集的程式碼食譜。
《C# Cookbook》提供了這種新程式語言的權威解決方案和範例集合。食譜涵蓋從簡單任務到更複雜的問題,並根據你作為 C# 程式設計師的經驗進展所需解決的問題類型進行組織。幾乎每個食譜都包含完整的、經過文檔記錄的程式碼範例,展示如何解決特定問題,並討論底層技術的運作方式,以及在適當的情況下討論替代方案、限制和其他考量。
《C# Cookbook》中的食譜分為十七個章節,每個章節專注於創建 C# 解決方案的特定主題。在涵蓋的主題中,你會發現:
- C# 中的數值資料類型
- 字串和字元
- 類別和結構
- 異常處理
- 委派和事件
- 正規表達式
- 資料結構和演算法
- 網路
- 安全性
- 不安全的程式碼
你不需要成為經驗豐富的 C# 或 .NET 開發者才能使用這本書。《C# Cookbook》設計適合各級使用者,食譜針對的是需要立即解決問題的實際開發者,而不是先學習大量理論。透過這本指南,所有開發者都能學習並提升對語言和 .NET Framework Class Libraries 的掌握。
目錄
前言
1. 數字
1.1 確定分數與浮點值之間的近似相等
1.2 將度數轉換為弧度
1.3 將弧度轉換為度數
1.4 使用位元補數運算子與各種資料類型
1.5 測試是否為偶數或奇數
1.6 獲取數字的最重要或最不重要位元
1.7 將其他進位制的數字轉換為十進位
1.8 確定字串是否為有效數字
1.9 四捨五入浮點值
1.10 不同的四捨五入演算法
1.11 將攝氏轉換為華氏
1.12 將華氏轉換為攝氏
1.13 安全地執行窄化數字轉換
1.14 找出直角三角形的任意三邊長
1.15 找出直角三角形的角度
2. 字串和字元
2.1 確定字元的類型
2.2 確定字元是否在指定範圍內
2.3 比較兩個字元時控制大小寫敏感性
2.4 找出字串中所有字元的出現位置
2.5 找出一個字串在另一個字串中所有出現的位置
2.6 簡易的分詞器
2.7 比較兩個字串時控制大小寫敏感性
2.8 將字串與第二個字串的開頭或結尾進行比較
2.9 在字串中插入文本
2.10 移除或替換字串中的字元
2.11 將二進位資料編碼為 Base64
2.12 解碼 Base64 編碼的二進位
2.13 將作為 Byte[ ] 返回的字串轉換回字串
2.14 將字串傳遞給僅接受 Byte[ ] 的方法
2.15 將字串轉換為其等效的值類型
2.16 格式化字串中的資料
2.17 創建分隔字串
2.18 從分隔字串中提取項目
2.19 設定字串可以包含的最大字元數
2.20 遍歷字串中的每個字元
2.21 改善字串比較性能
2.22 改善 StringBuilder 性能
2.23 修剪字串開頭和/或結尾的字元
3. 類別和結構
3.1 創建聯合型結構
3.2 允許類型以字串形式表示自己
3.3 將物件的字串表示轉換為實際物件
3.4 通過具體或抽象基類實現多型
3.5 使類型可排序
3.6 使類型可搜尋
3.7 間接重載 +=、-=、/= 和 *= 運算子
3.8 間接重載 &&、|| 和 ?: 運算子
3.9 改善結構的 Equals 方法性能
3.10 開啟或關閉位元
3.11 創建無錯誤的表達式
3.12 最小化(減少)布林邏輯
3.13 以語言無關的方式在簡單類型之間轉換
3.14 確定是否使用轉換運算子、as 運算子或 is 運算子
3.15 使用 as 運算子進行轉換
3.16 使用 is 運算子確定變數的類型
3.17 通過介面實現多型
3.18 在多個物件類型上調用相同的方法
3.19 使用介面添加通知回調
3.20 使用多個進入點為應用程式版本控制
3.21 防止創建僅部分初始化的物件
3.22 從方法返回多個項目
3.23 解析命令列參數
3.24 改裝類別以與 COM 互操作
3.25 在執行時初始化常數欄位
3.26 編寫與最廣泛範圍的管理語言相容的程式碼
3.27 在類別中實現嵌套的 foreach 功能
3.28 建立可克隆的類別
3.29 確保物件的釋放
3.30 通過管理程式碼釋放 COM 物件
3.31 創建物件快取
3.32 單一實例物件
3.33 選擇序列化器
3.34 創建自定義列舉器
3.35 回滾物件變更
3.36 處理非管理資源
3.37 確定何時發生裝箱和拆箱
4. 列舉
4.1 將列舉值顯示為字串
4.2 將純文字轉換為等效的列舉值
4.3 測試是否為有效的列舉值
4.4 測試是否為有效的標誌列舉
4.5 在位元遮罩中使用列舉成員
4.6 確定是否設置了一個或多個列舉標誌
5. 異常處理
5.1 驗證關鍵參數
5.2 指示異常的來源
5.3 選擇何時拋出特定異常
5.4 單獨處理衍生異常
5.5 確保在使用 finally 區塊時不會丟失異常
5.6 處理通過反射調用的方法拋出的異常
5.7 調試加載組件時的問題
5.8 HRESULT-異常映射
5.9 處理用戶自定義的 HRESULT
5.10 防止未處理的異常
5.11 顯示異常資訊
5.12 快速找到問題的根源
5.13 創建新的異常類型
5.14 獲取堆疊追蹤
5.15 在第一次機會異常時中斷
5.16 防止惡意的 TypeInitializationException
5.17 處理從異步委派拋出的異常
6. 診斷
6.1 控制生產代碼中的追蹤輸出
6.2 提供對調試/追蹤輸出進行細粒度控制
6.3 創建自定義開關類別
6.4 一個以 XML 格式輸出資訊的自定義追蹤類別
6.5 條件編譯程式碼區塊
6.6 確定進程是否停止響應
6.7 在應用程式中使用一個或多個事件日誌
6.8 更改自定義事件日誌的最大大小
6.9 搜尋事件日誌條目
6.10 監視事件日誌中特定條目
6.11 找出屬於特定事件日誌的所有來源
6.12 實現簡單的性能計數器
6.13 實現需要基礎計數器的性能計數器
6.14 啟用/禁用複雜的追蹤程式碼
7. 委派和事件
7.1 控制多播委派中委派何時及是否觸發
7.2 獲取多播委派中每個委派的返回值
7.3 單獨處理多播委派中每個委派的異常
7.4 將同步委派轉換為異步委派
7.5 向密封類別添加事件
7.6 在事件中傳遞專用參數
7.7 高級介面搜尋機制
7.8 高級成員搜尋機制
7.9 觀察新增和修改的情況