C# 本事
C# 本事
關於本書
本書的目的是介紹 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:列舉器
- chapter 8:LINQ
預計會加入的內容:async/await 語法。
Bundles that include this book
書籍目錄
-
關於本書
- 本書定位
- 閱讀方法
- 書寫慣例
- 本書用到的工具
- 範例程式與補充資料
- 版本更新紀錄
- 關於作者
-
1. C# 基礎語法
-
1.1 使用
var
宣告隱含型別 -
1.2 使用
dynamic
宣告動態型別 -
1.3 可為
null
的型別- 1.3.1 宣告與初始化
- 1.3.2 賦值與取值
- 1.3.3 判斷是否有值
-
1.3.4 與非
Nullable
型別混用
-
1.4 物件初始設定式
- 1.4.1 集合的初始設定式
- 1.5 自動實作屬性
-
1.6 匿名型別
- 1.6.1 投射初始設定式
- 1.6.2 注意事項
- 1.7 擴充方法
- 1.8 下一步
-
1.1 使用
-
2. 泛型
-
2.1 為什麼要有泛型?
- 2.1.1 手動轉型的問題
- 2.1.2 土法煉鋼
- 2.1.3 泛型之美
-
2.2 細說泛型
- 2.2.1 泛型、型別參數、建構的型別
- 2.2.2 泛型是型別的樣板
- 2.2.3 建構式與解構式
- 2.2.4 預設值的表示法
- 2.2.5 型別參數的條件約束
- 2.2.6 泛型介面與結構
-
2.3 泛型方法
- 2.3.1 型別推斷
- 2.3.2 擴充方法與泛型類別
- 2.4 泛型與 C++ 樣板的差異
-
2.5 泛型的型別相容問題
- 2.5.1 核心概念:型別相容
- 2.5.2 Covariance
- 2.5.3 Contravariance
- 2.6 重點回顧
-
2.1 為什麼要有泛型?
-
3. 委派與 Lambda 表示式
-
3.1 委派
- 3.1.1 為什麼要用委派?
- 3.1.2 C# 1.0 的寫法
- 3.1.3 C# 2.0 的寫法
- 3.1.4 C# 3.0 的寫法
- 3.1.5 泛型委派
-
3.2 Lambda 表示式
- 3.2.1 運算式 lambda
- 3.2.2 陳述式 lambda
- 3.2.3 重點整理:概念圖
- 3.2.4 外部變數
- 3.2.5 運算式樹
- 3.3 總結
-
3.1 委派
-
4. 事件
-
4.1 基礎觀念
- 4.1.1 事件驅動程式設計
- 4.1.2 發行-訂閱模式
-
4.2 使用委派來實作事件
- 4.2.1 宣告委派型別
- 4.2.2 宣告委派變數
- 4.2.3 觸發事件
- 4.2.4 訂閱事件
- 4.2.5 加入與移除事件處理常式
-
4.3 使用
event
關鍵字- 4.3.1 提供觸發事件的方法
-
4.4 .NET 事件程式設計的慣例
- 4.4.1 不要傳回值
- 4.4.2 在參數列提供來源物件
-
4.4.3 使用
EventArgs
來包裝參數 -
4.4.4 使用現成的
EventHandler
型別
-
4.5 更好的設計
- 4.5.1 事件參數僅提供唯讀屬性
- 4.5.2 避免意外中斷事件處理流程
- 4.5.3 使用事件存取子
- 4.5.4 管理大量事件
-
4.6 委派 vs. 事件
- 4.6.1 相同之處
- 4.6.2 相異之處
- 4.7 總結
-
4.1 基礎觀念
-
5. C# 6
-
5.1
nameof
表示式 - 5.2 字串插值
-
5.3
Null
條件運算子 -
5.4 唯讀自動實作屬性
- 5.4.1 微妙議題:明確實作介面的唯讀屬性
- 5.5 自動屬性的初始設定式
-
5.6 以表示式為本體的成員
- 5.6.1 C# 7 的改進
- 5.7 索引初始設定式
-
5.8
using static
陳述式 - 5.9 例外篩選條件
-
5.10
catch
和finally
區塊中的await
-
5.1
-
6. C# 7
- 6.1 宣告輸出變數
-
6.2 Tuple 語法
- 6.2.1 Tuple 元素名稱推導
- 6.2.2 無法推導元素名稱的情形
- 6.2.3 Tuple 與匿名方法
-
6.3 分解式
- 6.3.1 為類別加入分解式
- 6.3.2 巢狀分解
-
6.4 模式匹配
-
6.4.1 模式匹配之
is
陳述式 -
6.4.2 模式匹配之
switch
陳述式
-
6.4.1 模式匹配之
-
6.5 區域函式
- 6.5.1 捕捉區域變數
- 6.6 更好讀的數值表示法
-
6.7 Ref Local 與 Ref Return
- 6.7.1 Ref Local
- 6.7.2 Ref Return
- 6.7.3 重新指派 Ref Local
- 6.7.4 用在哪裡?
- 6.7.5 Ref 條件運算式
- 6.7.6 Ref readonly
-
6.8
throw
運算式 -
6.9
async Main
方法 -
6.10
default
運算式- 6.10.1 用於泛型
-
6.11 實值型別具備參考語意
- 6.11.1 in 參數
- 6.11.2 唯讀結構
- 6.11.3 只能放在堆疊的結構(ref struct)
- 6.12 非後置的具名引數
-
6.13
private protected
修飾詞 - 6.14 結語
-
7. C# 8
- 7.1 預設介面實作
-
7.2 可為 Null 的參考型別
- 7.2.1 開啟 Nullable Reference Types 功能
- 7.2.2 在個別檔案中使用 #nullable 指示詞
- 7.2.3 專案與方案層級的設定
- 7.3 重點整理
-
8. 列舉器
-
8.1 從
foreach
說起 -
8.2
IEnumerator
介面 -
8.3
IEnumerable
介面 - 8.4 設計「可列舉的」類別
-
8.5
IEnumerable<T>
與IEnumerator<T>
介面 - 8.6 重點回顧
-
8.1 從
-
9. LINQ
-
9.1 基本觀念
- 9.1.1 C# 的 LINQ 表示式
- 9.1.2 串接語法
- 9.1.3 LINQ 提供者
-
9.1.4
IEnumerable<T>
vs.IQueryable<T>
- 9.1.5 延遲執行
- 9.1.6 重複求值
-
9.2 實務練習
- 9.2.1 篩選
- 9.2.2 排序
- 9.2.3 尋找單一項目
- 9.2.4 判斷是否符合特定條件
- 9.2.5 轉換物件
- 9.2.6 計數、最大/最小值、平均、彙總
- 9.2.7 分組
- 9.2.8 產生序列
- 9.2.9 擴增查詢結果
- 9.2.10 父子關聯
-
9.3 LINQ 進階練習
- 9.3.1 誰的分數最高?
- 9.4 重點回顧
-
9.1 基本觀念
-
10. 非同步呼叫
- 10.1 結語
-
附錄 A:Visual Studio 的專案設定
- 指定編譯時所使用的 C# 版本
- 調整編譯器的警告
-
附錄 B:安裝與設定 Visual Studio Code
- 安裝
- 版權頁
- 備註
關於出版社

This book is published on Leanpub by Ministep Books
Leanpub 無條件、無風險的 100% 滿意保證
從付款之後的 60 天內,只要點個兩下,你就可以完成退書並且取回先前支付的全數金額。退書是採用人工作業,因此可能需要花幾天的時間才能完成整個程序。
See full terms.
Do Well. Do Good.
Authors have earned$11,721,492writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
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), EPUB (for phones and tablets) and MOBI (for 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
Top Books
Recipes for Decoupling
Matthias NobackWrite software that survives
CQRS by Example
Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary- Leverage your Software Architecture skills by learning everything about CQRS in detail with lots of examples
- Develop faster applications by applying CQRS and fostering Read Models and Projections
- Learn how to apply CQRS into a brownfield project from a pragmatic approach
OpenIntro Statistics
David Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntroA complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
Maîtriser Apache JMeter
Philippe Mouawad, Bruno Demion (Milamber), and Antonio Gomes RodriguesToute la puissance d'Apache JMeter expliquée par ses commiteurs et utilisateurs experts. De l'intégration continue en passant par le Cloud, vous découvrirez comment intégrer JMeter à vos processus "Agile" et Devops.
If you're looking for the newer english version of this book, go to Master JMeter : From load testing to DevOps
C++20 - The Complete Guide
Nicolai M. JosuttisAll new language and library features of C++20 (for those who know previous C++ versions).
The book presents all new language and library features of C++20. Learn how this impacts day-to-day programming, to benefit in practice, to combine new features, and to avoid all new traps.
Buy early, pay less, free updates.
Other books:
Jetpack Compose internals
Jorge CastilloJetpack Compose is the future of Android UI. Master how it works internally and become a more efficient developer with it. You'll also find it valuable if you are not an Android dev. This book provides all the details to understand how the Compose compiler & runtime work, and how to create a client library using them.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Mastering STM32 - Second Edition
Carmine NovielloWith more than 1200 microcontrollers, STM32 is probably the most complete ARM Cortex-M platform on the market. This book aims to be the most complete guide around introducing the reader to this exciting MCU portfolio from ST Microelectronics and its official CubeHAL and STM32CubeIDE development environment.
Rector - The Power of Automated Refactoring
Matthias Noback and Tomas VotrubaLearn how to automatically and continuously upgrade and improve your PHP code base
The Hundred-Page Machine Learning Book
Andriy BurkovEverything you really need to know in Machine Learning in a hundred pages.
Top Bundles
- #2
CCIE Service Provider Ultimate Study Bundle
2 Books
Piotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification... - #3
Pattern-Oriented Memory Forensics and Malware Detection
2 Books
This training bundle for security engineers and researchers, malware and memory forensics analysts includes two accelerated training courses for Windows memory dump analysis using WinDbg. It is also useful for technical support and escalation engineers who analyze memory dumps from complex software environments and need to check for possible... - #4
Software Architecture
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #5
Static Analysis and Automated Refactoring
2 Books
As PHP developers we are living in the "Age of Static Analysis". We can use a tool like PHPStan to learn about potential bugs before we ship our code to production, and we can enforce our team's programming standards using custom PHPStan rules. Recipes for Decoupling by Matthias Noback teaches you in great detail how to do this, while also... - #9
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon...