惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Vercel News
Vercel News
Y
Y Combinator Blog
D
DataBreaches.Net
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
WordPress大学
WordPress大学
H
Help Net Security
GbyAI
GbyAI
C
Check Point Blog
L
LangChain Blog
小众软件
小众软件
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
G
Google Developers Blog
月光博客
月光博客
V
V2EX
M
MIT News - Artificial intelligence
博客园 - 叶小钗

博客园 - ProjectDD

NET 中 Async/Await 的演进:从状态机到运行时优化的 Continuation C# 指针用法小结 C# BinaryPrimitives 类 C# 内存对齐 linq 查询关于 from子句 关于C# await的一点新理解 关于排序算法 C# Dev Kit 经常导致崩溃 不太会用Span<T> 看文档上的优点估摸着试试 span,memory,ArrayPool,MemoryPool,等的性能对比 C# simd 性能雷点记录 高中生理解梯度为何是方向导数极大值 概略 deep net 通过relu 进行函数逼近 win10 下安装 rust 的 依赖配置,通过vs2022 C# 有多需要aot 24个希腊字母的中文拼音版 英语发音探讨 sagemath 9.x 下的 jupyter 工作路径设置 Serializing delegates is not supported on this platform
C# 模式匹配里应该注意的几点
ProjectDD · 2022-10-09 · via 博客园 - ProjectDD

马上就要出C#11了,近几个版本模式匹配一直在更新,参见官网:模式 - C# 参考 | Microsoft Learn

使用模式主要就是switch, 分两种 switch 语句和表达式, 

语句:(功能全面)

switch(i){

case const_exp1: /*customer logic*/ break;

case const_exp2: /*customer logic*/ break;

//...

default /*customer logic*/ break;

}

表达式:(需要有返回值)

x=i switch{

const_exp1=>/*customer expression*/,

const_exp2=>/*customer expression*/,

//...

_=>/*customer expression*/,

};

需要特别指出值得注意的是

1,常量声明式就是等于的意思 

2,关系模式(>,>=,<,<=): 由关系运算左置来表达,注意此关系模式中不包括==,!= , ==这个直接属于声明模式,!= 则属于 not 逻辑模式之列

3,模式匹配,依赖于常量表达式,否则需要启用写法比较冗余 难看的 when子句,when子句相当于一个一般逻辑表达式,范围全面但写法冗余最好别用