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
Table of Contents
-
關於本書
- 本書定位
- 閱讀方法
- 書寫慣例
- 本書用到的工具
- 範例程式與補充資料
- 版本更新紀錄
- 關於作者
-
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 類似參考型別的結構
- 6.12 非後置的具名引數
- 6.13 private protected 修飾詞
- 6.14 結語
-
7. 列舉器
-
7.1 從
foreach
說起 -
7.2
IEnumerator
介面 -
7.3
IEnumerable
介面 - 7.4 設計「可列舉的」類別
-
7.5
IEnumerable<T>
與IEnumerator<T>
介面 - 7.6 重點回顧
-
7.1 從
-
8. LINQ
-
8.1 基本觀念
- 8.1.1 C# 的 LINQ 表示式
- 8.1.2 串接語法
- 8.1.3 LINQ 提供者
-
8.1.4
IEnumerable<T>
vs.IQueryable<T>
- 8.1.5 延遲執行
- 8.1.6 重複求值
-
8.2 實務練習
- 8.2.1 篩選
- 8.2.2 排序
- 8.2.3 尋找單一項目
- 8.2.4 判斷是否符合特定條件
- 8.2.5 轉換物件
- 8.2.6 計數、最大/最小值、平均、彙總
- 8.2.7 分組
- 8.2.8 產生序列
- 8.2.9 擴增查詢結果
- 8.2.10 父子關聯
-
8.3 LINQ 進階練習
- 8.3.1 誰的分數最高?
- 8.4 重點回顧
-
8.1 基本觀念
-
附錄 A:Visual Studio 的專案設定
- 指定編譯時所使用的 C# 版本
- 調整編譯器的警告
-
附錄 B:安裝與設定 Visual Studio Code
- 安裝
- 版權頁
- 備註
關於出版社

This book is published on Leanpub by Ministep Books
Authors have earned$9,913,563writing, 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
Leanpub 無條件、無風險的 100% 滿意保證
從付款之後的 45 天內,只要點個兩下,你就可以完成退書並且取回先前支付的全數金額。退書是採用人工作業,因此可能需要花幾天的時間才能完成整個程序。
See full terms.
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
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Continuous Delivery Pipelines
Dave FarleyThis practical handbook provides a step-by-step guide for you to get the best continuous delivery pipeline for your software.
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.
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Introductory Statistics with Randomization and Simulation
Mine Cetinkaya-Rundel, Christopher Barr, OpenIntro, and David DiezA complete foundation for Statistics, also serving as a foundation for Data Science, that introduces inference using randomization and simulation while covering traditional methods.
Leanpub revenue supports OpenIntro, so we can provide free desk copies to teachers interested in using our books in the classroom.
More resources: openintro.org.
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.
Java OOP Done Right
Alan MellorObject Oriented Programming is still a great way to create clean, maintainable code. But only if you use it right.
This book gives you 25 years of OO best practice, ready to use.
You'll learn to design objects behaviour-first, use TDD to help, then confidently apply Design Patterns, SOLID principles and Refactoring to make clean, crafted code.
Introducing EventStorming
Alberto BrandoliniThe deepest tutorial and explanation about EventStorming, straight from the inventor.
Discrete Mathematics for Computer Science
Alexander Shen, Alexander S. Kulikov, Vladimir Podolskii, and Aleksandr GolovnevThis book supplements the DM for CS Specialization at Coursera and contains many interactive puzzles, autograded quizzes, and code snippets. They are intended to help you to discover important ideas in discrete mathematics on your own. By purchasing the book, you will get all updates of the book free of charge when they are released.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
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... - #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
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #4
Modern C++ by Nicolai Josuttis
2 Books
- #5
CCDE Practical Studies (All labs)
3 Books
CCDE lab - #6
"The C++ Standard Library" and "Concurrency with Modern C++"
2 Books
Get my books "The C++ Standard Library" and "Concurrency with Modern C++" in a bundle. The first book gives you the details you should know about the C++ standard library; the second one dives deeper into concurrency with modern C++. In sum, you get more than 600 pages full of modern C++ and about 250 source files presenting the standard library... - #7
Mastering Containers
2 Books
Docker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes! - #8
The Future of Digital Health
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 and how technology giants such as Amazon or Google want to conquer... - #9
Django for Beginners/APIs/Professionals
3 Books
- #10
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité...