Leanpub Header

Skip to main content

C# 本事

(涵蓋 C# 10)

本書挑選了 C# 語法當中那些特別重要、實用的部分,並隨著 C# 新版本更新內容(免費更新!),希望能幫助讀者迅速掌握 C# 最新的進階語法。

Minimum price

$18.00

$19.95

You pay

$19.95
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
350
Readers
203
Pages
About

About

About the Book

本書的目的是介紹 C# 程式語言的重要特色,以及實務上常用的 .NET 類別(例如集合、LINQ 等)。也就是說,對於像是變數、迴圈、if...else 等基礎語法,本書都不會介紹。我不想讓這本書便得太厚而難以消化。

目前進行中的章節大致如下:

  • chapter 1: C# 基礎語法的重要部分。請注意這裡的「基礎語法」,指的並不是如迴圈(例如 for、foreach)、決策(例如 if...else、switch...case)等基本元素,而是其他稍微進階一點、或更便捷的 C# 語法,包括:可為 null 的型別( nullable types)、 物件初始設定式、 自動實作屬性、匿名型別、擴充方法等等。
  • chapter 2:泛型
  • chapter 3:委派與 Lambda 表示式 
  • chapter 4:事件  
  • chapter 5:C# 6
  • chapter 6:C# 7
  • chapter 7:C# 8
  • chapter 8:C# 9
  • chapter 9:C# 10
  • chapter 10:列舉器
  • chapter 11:LINQ

預計會加入的內容:async/await 語法。

Share this book

Categories

Author

About the Author

Michael Tsai

Hi there! I'm a technical writer with 10+ years of experience in software development and 16 awards of Microsoft .NET MVP.

著作:《C# 本事》、《.NET 本事:非同步程式設計》、《.NET 相依性注入》(簡體中文版:.NET 依賴注入)

譯作: 軟體構築美學 (Brownfield Application Development in .NET)、物件導向分析設計與應用(Object-Oriented Analysis and Design with Applications 3rd Edition)、軟體工程與 Microsoft Visual Studio Team System.

部落格: https://www.huanlintalk.com

Contents

Table of Contents

關於本書

  1. 本書定位
  2. 閱讀方法
  3. 書寫慣例
  4. 本書用到的工具
  5. 範例程式與補充資料
  6. 版本更新紀錄

關於作者

C# 基礎語法

  1. 使用 var 宣告隱含型別
  2. 使用 dynamic 宣告動態型別
  3. 可為 null 的型別
  4. 宣告與初始化
  5. 賦值與取值
  6. 判斷是否有值
  7. 與非 Nullable 型別混用
  8. 物件初始設定式
  9. 集合的初始設定式
  10. 自動實作屬性
  11. 匿名型別
  12. 投射初始設定式
  13. 注意事項
  14. 擴充方法
  15. 下一步

泛型

  1. 為什麼要有泛型?
  2. 手動轉型的問題
  3. 土法煉鋼
  4. 泛型之美
  5. 細說泛型
  6. 泛型、型別參數、建構的型別
  7. 泛型是型別的樣板
  8. 建構式與解構式
  9. 預設值的表示法
  10. 型別參數的條件約束
  11. 泛型介面與結構
  12. 泛型方法
  13. 型別推斷
  14. 擴充方法與泛型類別
  15. 泛型與 C++ 樣板的差異
  16. 泛型的型別相容問題
  17. 核心概念:型別相容
  18. Covariance
  19. Contravariance
  20. 重點回顧

委派與 Lambda 表示式

  1. 委派
  2. 為什麼要用委派?
  3. C# 1.0 的寫法
  4. C# 2.0 的寫法
  5. C# 3.0 的寫法
  6. 泛型委派
  7. Lambda 表示式
  8. 運算式 lambda
  9. 陳述式 lambda
  10. 重點整理:概念圖
  11. 外部變數
  12. 運算式樹
  13. 總結

事件

  1. 基礎觀念
  2. 事件驅動程式設計
  3. 發行-訂閱模式
  4. 使用委派來實作事件
  5. 宣告委派型別
  6. 宣告委派變數
  7. 觸發事件
  8. 訂閱事件
  9. 加入與移除事件處理常式
  10. 使用 event 關鍵字
  11. 提供觸發事件的方法
  12. .NET 事件程式設計的慣例
  13. 不要傳回值
  14. 在參數列提供來源物件
  15. 使用 EventArgs 來包裝參數
  16. 使用現成的 EventHandler 型別
  17. 更好的設計
  18. 事件參數僅提供唯讀屬性
  19. 避免意外中斷事件處理流程
  20. 使用事件存取子
  21. 管理大量事件
  22. 委派 vs. 事件
  23. 相同之處
  24. 相異之處
  25. 總結

C# 6

  1. nameof 表示式
  2. 字串插值
  3. Null 條件運算子
  4. 唯讀自動實作屬性
  5. 微妙議題:明確實作介面的唯讀屬性
  6. 自動屬性的初始設定式
  7. 以表示式為本體的成員
  8. C# 7 的改進
  9. 索引初始設定式
  10. using static 陳述式
  11. 例外篩選條件
  12. catchfinally 區塊中的 await

C# 7

  1. 宣告輸出變數
  2. Tuple 語法
  3. Tuple 元素名稱推導
  4. 無法推導元素名稱的情形
  5. Tuple 與匿名方法
  6. 分解式
  7. 為類別加入分解式
  8. 巢狀分解
  9. 模式匹配
  10. 模式匹配之 is 陳述式
  11. 模式匹配之 switch 陳述式
  12. 區域函式
  13. 捕捉區域變數
  14. 更好讀的數值表示法
  15. Ref Local 與 Ref Return
  16. Ref Local
  17. Ref Return
  18. 重新指派 Ref Local
  19. 用在哪裡?
  20. Ref 條件運算式
  21. Ref readonly
  22. throw 運算式
  23. async Main 方法
  24. default 運算式
  25. 用於泛型
  26. 實值型別具備參考語意
  27. in 參數
  28. 唯讀結構
  29. 只能放在堆疊的結構(ref struct)
  30. 非後置的具名引數
  31. private protected 修飾詞
  32. 結語

C# 8

  1. 結構成員可宣告唯讀
  2. 預設介面實作
  3. 可為 Null 的參考型別
  4. 開啟 Nullable Reference Types 功能
  5. 在個別檔案中使用 #nullable 指示詞
  6. 專案與方案層級的設定
  7. 重點整理

C# 9

  1. 頂層語句
  2. new 物件時可省略型別
  3. Init-only Setter
  4. 記錄
  5. 編譯器產生的程式碼
  6. 複製物件
  7. ToString 方法
  8. Equals 方法
  9. Deconstruct 方法
  10. 結語
  11. 樣式比對的改進
  12. 改寫回傳型別
  13. IEnumerator 更容易支援 foreach
  14. Lambda 捨棄參數
  15. Interop 方面的改進
  16. 其他改進

C# 10

  1. File-scoped 命名空間
  2. 全域引用
  3. 使用 C# 檔案來管理全域引用
  4. 透過專案檔來管理全域引用
  5. 字串常數插補
  6. 巢狀屬性樣式
  7. Lambda 語法的改進
  8. 分解式的改進
  9. 記錄的改進
  10. 以結構實作的記錄
  11. ToString 方法可被密封
  12. 結構的改進
  13. 匿名型別的非破壞式變形
  14. 字串插補的效能改進
  15. 字串插補處理器
  16. CallerArgumentExpression 特徵項
  17. AsyncMethodBuilder 特徵項可套用至方法
  18. 其他改進

列舉器

  1. foreach 說起
  2. IEnumerator 介面
  3. IEnumerable 介面
  4. 設計「可列舉的」類別
  5. IEnumerable<T>IEnumerator<T> 介面
  6. 重點回顧

LINQ

  1. 基本觀念
  2. C# 的 LINQ 表示式
  3. 串接語法
  4. LINQ 提供者
  5. IEnumerable<T> vs. IQueryable<T>
  6. 延遲執行
  7. 重複求值
  8. 實務練習
  9. 篩選
  10. 排序
  11. 尋找單一項目
  12. 判斷是否符合特定條件
  13. 轉換物件
  14. 計數、最大/最小值、平均、彙總
  15. 分組
  16. 產生序列
  17. 擴增查詢結果
  18. 父子關聯
  19. LINQ 進階練習
  20. 誰的分數最高?
  21. 重點回顧

附錄 A:Visual Studio 的專案設定

  1. 指定編譯時所使用的 C# 版本
  2. 調整編譯器的警告

附錄 B:安裝與設定 Visual Studio Code

  1. 安裝

版權頁

  1. C# 本事
  2. 圖片來源

About the Publisher

About the Publisher

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub