Clean Code in C#: Refactor your legacy C# code base and improve application performance by applying best practices

Jason Alls (Author)



Key Features

  • Write code that cleanly integrates with other systems while maintaining well-defined software boundaries
  • Understand how coding principles and standards enhance software quality
  • Learn how to avoid common errors while implementing concurrency or threading

Book Description

Traditionally associated with developing Windows desktop applications and games, C# is now used in a wide variety of domains, such as web and cloud apps, and has become increasingly popular for mobile development. Despite its extensive coding features, professionals experience problems related to efficiency, scalability, and maintainability because of bad code. Clean Code in C# will help you identify these problems and solve them using coding best practices.

The book starts with a comparison of good and bad code, helping you understand the importance of coding standards, principles, and methodologies. You'll then get to grips with code reviews and their role in improving your code while ensuring that you adhere to industry-recognized coding standards. This C# book covers unit testing, delves into test-driven development, and addresses cross-cutting concerns. You'll explore good programming practices for objects, data structures, exception handling, and other aspects of writing C# computer programs. Once you've studied API design and discovered tools for improving code quality, you'll look at examples of bad code and understand which coding practices you should avoid.

By the end of this clean code book, you'll have the developed skills you need in order to apply industry-approved coding practices to write clean, readable, extendable, and maintainable C# code.

What you will learn

  • Write code that allows software to be modified and adapted over time
  • Implement the fail-pass-refactor methodology using a sample C# console application
  • Address cross-cutting concerns with the help of software design patterns
  • Write custom C# exceptions that provide meaningful information
  • Identify poor quality C# code that needs to be refactored
  • Secure APIs with API keys and protect data using Azure Key Vault
  • Improve your code's performance by using tools for profiling and refactoring

Who this book is for

This coding book is for C# developers, team leads, senior software engineers, and software architects who want to improve the efficiency of their legacy systems. A strong understanding of C# programming is required.



  • 撰寫與其他系統整合並保持良好定義的軟體邊界的程式碼

  • 了解編碼原則和標準如何提升軟體品質

  • 學習在實現並行性或多執行緒時避免常見錯誤


C# 傳統上與開發 Windows 桌面應用程式和遊戲相關聯,現在在各種領域中使用,例如網路和雲端應用程式,並且在移動開發中越來越受歡迎。儘管具有廣泛的編碼功能,專業人士仍然因為糟糕的程式碼而遇到效能、可擴展性和可維護性的問題。《C# 清潔程式碼》將幫助您識別這些問題並使用最佳編碼實踐來解決它們。

本書從好壞程式碼的比較開始,幫助您了解編碼標準、原則和方法論的重要性。然後,您將瞭解程式碼審查及其在改進程式碼方面的作用,同時確保您遵守業界公認的編碼標準。本書涵蓋了單元測試,深入探討了測試驅動開發,並處理了橫切關注點。您將探索對象、資料結構、例外處理和其他撰寫 C# 電腦程式的方面的良好編程實踐。在研究了 API 設計並發現了改善程式碼品質的工具之後,您將查看糟糕程式碼的示例,並了解應該避免哪些編碼實踐。

通過閱讀本書,您將具備應用業界認可的編碼實踐來撰寫乾淨、可讀、可擴展和可維護的 C# 程式碼所需的技能。


  • 撰寫可隨時間修改和適應的程式碼

  • 使用示範的 C# 控制台應用程式實施失敗-通過-重構方法論

  • 使用軟體設計模式處理橫切關注點

  • 撰寫提供有意義資訊的自訂 C# 例外

  • 識別需要重構的低品質 C# 程式碼

  • 使用 API 金鑰保護 API 並使用 Azure 金鑰保管庫保護資料

  • 使用性能分析和重構工具改善程式碼的效能


本書適合 C# 開發人員、團隊領導、高級軟體工程師和軟體架構師,他們希望提高遺留系統的效率。需要具備扎實的 C# 編程知識。


Jason Alls has been programming for over 21 years using Microsoft technologies. Working with an Australasian company, he started his career developing call center management reporting software used by global clients including telecom providers, banks, airlines, and the police. He then moved on to develop GIS marketing applications and worked in the banking sector performing data migrations between Oracle and SQL Server. Certified as an MCAD in C# since 2005, he has been involved in the development of various desktop, web, and mobile applications.


Jason Alls已經使用Microsoft技術進行編程超過21年。他在一家澳洲公司工作,開始他的職業生涯時開發了一款被全球客戶使用的呼叫中心管理報告軟件,包括電信提供商、銀行、航空公司和警察。然後,他轉而開發GIS營銷應用程序,並在銀行業中進行Oracle和SQL Server之間的數據遷移工作。自2005年以來,他獲得了C#的MCAD認證,並參與了各種桌面、網絡和移動應用程序的開發。


  1. Coding Standards and Principles in C#
  2. Code Review – Process and Importance
  3. Classes, Objects, and Data Structures
  4. Writing Clean Functions
  5. Exception Handling
  6. Unit Testing
  7. End-to-End System Testing
  8. Threading and Concurrency
  9. Designing and Developing APIs
  10. Securing APIs with API Keys and Azure Key Vault
  11. Addressing Cross-Cutting Concerns
  12. Using Tools to Improve Code
  13. Refactoring C# Code – Identifying Code Smells
  14. Refactoring C# Code – Implementing Design Patterns


- C# 程式碼標準和原則
- 程式碼審查 - 流程和重要性
- 類別、物件和資料結構
- 撰寫乾淨的函式
- 例外處理
- 單元測試
- 系統端對端測試
- 多執行緒和並行性
- 設計和開發 API
- 使用 API 金鑰和 Azure Key Vault 保護 API
- 處理橫切關注點
- 使用工具改善程式碼
- 重構 C# 程式碼 - 辨識程式碼異味
- 重構 C# 程式碼 - 實作設計模式