Skip to content

Commit a4827fb

Browse files
committed
publish episode 55
1 parent 9a63e76 commit a4827fb

File tree

2 files changed

+176
-1
lines changed

2 files changed

+176
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
- GitHub
1212
- [Web](https://www.fungkao.net/searchByTag/.NET%20Weekly)
13+
- [知乎](https://www.zhihu.com/column/c_1775053216763277312)
1314

1415
## 周刊
1516

1617
### 2024
1718

18-
**五月份** : [054](docs/episode-054.md) :high_brightness:
19+
**五月份** : [055](docs/episode-055.md) :high_brightness: | [第 054 期](docs/episode-054.md)
1920

2021
**四月份** : [第 053 期](docs/episode-053.md)
2122

docs/episode-055.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# .NET 每周分享第 53 期
2+
3+
## 卷首语
4+
5+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/43a5200e-6bbe-425a-8851-27449cc0b566)
6+
7+
5 月 21 号到 23 号是一年一度的 Microsoft Build 大会。大会中会涉及到很多 `.NET` 相关的内容,包裹 `Aspire`, `AI``.NET`, `Visual Studio` 等相关内容,如果感兴趣,可以线上加入。
8+
9+
## 行业资讯
10+
11+
1、[Avalonia项目宣布离开.NET基金会](https://github.com/AvaloniaUI/Avalonia/discussions/14666)
12+
13+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/ca12318a-e245-4d7c-b2e7-4d6484f05647)
14+
15+
Avalonia 团队宣布离开 `.NET Foundation` , 主要原因是想要让项目的主导权保留在开发核心团队。至于说具体的原因导致这次分手,声明中并没有提及,不过这一篇[文章](https://www.glennwatson.net/posts/dnf-problems-solutions)指出了 `.NET Foundation` 存在的问题和解决方案。
16+
17+
2、[Twitter .NET团队成员列表](https://twitter.com/i/lists/120961876)
18+
19+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/9af91c03-b051-4ae7-b70c-91f494edddc3)
20+
21+
`.NET` 团队成员的 `Twitter` 账号列表,关注他们,获得最新的资讯。
22+
23+
3、[Twitter Azure Cloud Advocates 列表](https://x.com/i/lists/847470660712505346)
24+
25+
`Azure Cloud Advocates` 团队成员的 `Twitter` 账号列表,关注他们,获得最新的资讯。
26+
27+
## 文章推荐
28+
29+
1、[跟 Stephen Toub 学习 Span](https://www.youtube.com/watch?v=5KdICNWOfEQ)
30+
31+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/3dbfb0b2-99dd-48d8-8b9b-ec8f95b60fb6)
32+
33+
`Span<T>` 是高性能 `C#` 代码的秘诀之一,`.NET` 社区大佬 `Stephen Toub` 深入探究了什么是 `Span` 并且从头完成一个简易版的实现。
34+
35+
首先 `Span<T>` 要解决什么问题?假设我们现在有一个方法是这样的,
36+
37+
```csharp
38+
private int Sum(int[] array)
39+
{
40+
int sum = 0;
41+
foreach(var val in array) sum += val;
42+
return sum;
43+
}
44+
```
45+
如果 `Sum` 方法的是求和数组的部分内容,那么方法的签名需要修改成这样
46+
47+
```
48+
private int Sum(int[] array, int offset, int length)
49+
{
50+
int sum = 0;
51+
for(int i = offset; i < length; i++) sum += array[offset+i];
52+
return sum;
53+
}
54+
```
55+
56+
这样会带来一个问题,就是这个方法只支持 `int[]` 数据类型,而 `C#` 中有很多类型都是表示连续的一段空间,比如 `List` 。所以 `Span` 这个类型结构就被提出来了,如果仅仅是表示一段连续空间,`Span` 并没有什么特殊之处,`C/C++` 中的指针,或者 `C#` 中的 `unsafe` 代码块也能够完成同样的工作,但是 `Span` 是内存安全的类型,而且还是一个值类型。
57+
58+
```csharp
59+
readonly ref struct MySpan<T>
60+
{
61+
private readonly ref T _reference;
62+
private readonly int _length;
63+
64+
65+
public MySpan(T[] array)
66+
{
67+
_reference = ref MemoryMarshal.GetArrayDataReference(array);
68+
_length = array.Length;
69+
}
70+
71+
public MySpan(ref T reference)
72+
{
73+
_reference = ref reference;
74+
_length = 1;
75+
}
76+
77+
public MySpan(ref T reference, int length)
78+
{
79+
_reference = ref reference;
80+
_length = length;
81+
}
82+
83+
84+
public ref T this[int index]
85+
{
86+
get
87+
{
88+
if (index < 0 || index >= _length)
89+
{
90+
throw new IndexOutOfRangeException();
91+
}
92+
93+
return ref Unsafe.Add(ref _reference, index);
94+
}
95+
}
96+
97+
public MySpan<T> Slice(int offset)
98+
{
99+
if (offset < 0 || offset >= _length)
100+
{
101+
throw new IndexOutOfRangeException();
102+
}
103+
104+
return new MySpan<T>(ref Unsafe.Add(ref _reference, offset), _length - offset);
105+
}
106+
}
107+
```
108+
109+
- `ref struct` 表明它只能用在方法中,而不能作为一个类的成员
110+
- `ref T _reference` 指向了连续空间的第一个元素
111+
- `ref T this[int index]` 说明连续空间的每个元素获取都是引用类型
112+
- `Unsafe.Add` 该方法避免了访问非法内存
113+
114+
2、[如何往已有的代码中添加 Nullability](https://blog.maartenballiauw.be/talk/2024/01/21/bringing-csharp-nullability-into-existing-code.html)
115+
116+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/fb6fb8d9-0bf4-47cb-9531-0c8d200bba5b)
117+
118+
`Nullable Reference Type``C# 8` 引入新的语法,它可以解决我们应用程序中的 `System.NullReferenceException` 的异常。但是从来没有银弹,这个工作需要程序在编译时候付出额外的付出。那么如何将已有的项目中开启这个功能呢?这个幻灯片介绍了其中的概念,方法和工具。
119+
120+
3、[JavaScript, TypeScript, C#代码实现对比](https://github.com/CharlieDigital/js-ts-csharp)
121+
122+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/3c4f8172-b019-4fbf-802f-0f8039432451)
123+
124+
对于前端开发人员,`JavaScript` 或者 `TypeScript` 是两个非常熟悉的开发编程语言。但是 `C#` 这种后端开发语言和 `JavaScript` 或者 `TypeScript` 却越来越像,它们在语法,工具链上面相互学习。
125+
126+
4、[.NET 9 将要移除 Swagger,那怎么替换呢?](https://www.youtube.com/watch?v=8xEkVmqlr4I)
127+
128+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/180ad6df-ebd3-4851-ba73-bc86537e7da1)
129+
130+
`.NET 9` 中将会移除之前内置的 `Swagger` ,并且全面拥抱 `OpenAPI`。那么以后就不会有 Swagger 页面,只有一个 Web API 定义的 JSON 文件,但是 [Scalar](https://github.com/scalar/scalar?tab=readme-ov-file) 项目可以将其渲染成漂亮的 UI。
131+
132+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/b957ddb3-cd97-4050-869a-1ec6d0442abb)
133+
134+
5、[.NET 9 LINQ 性能提升](https://steven-giesel.com/blogPost/783a404a-e39e-480f-bc99-a514a75d752d?utm_source=devdigest.today&utm_medium=website&utm_campaign=feature_promo&utm_content=link_click)
135+
136+
`.NET 9` 在 Linq 上继续有新的性能上的更新
137+
138+
- `Orderby.ToList`
139+
140+
通过 `Vector` 这个 SIMD 指令集提升
141+
142+
- `Chunk`
143+
144+
通过 `ReadOnlySpan` 提升性能
145+
146+
- `OfType`
147+
148+
通过处理特定的类型而不是通用的类型
149+
150+
- `Any`
151+
152+
通过调用 `TryGetNonEnumeratedCount` 方法提高性能
153+
154+
## 开源项目
155+
156+
1、[TeslaLogger](https://github.com/bassmaster187/TeslaLogger)
157+
158+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/6bc12ebc-ec11-4080-86d2-8fc610eb26d6)
159+
160+
TeslaLogger 是一个自托管的数据记录器,适用于您的 Tesla Model S/3/X/Y。目前,它支持 Raspberry Pi 3B、3B+、4B、Docker 和 Synology NAS。
161+
162+
2、[ILGPU](https://github.com/m4rs-mt/ILGPU)
163+
164+
ILGPU 是一个即时编译器(JIT),用于编写高性能 GPU 程序的 .NET 语言。ILGPU 完全用 C# 编写,没有任何本地依赖。它结合了 C++ AMP 的灵活性和便利性,以及 CUDA 程序的高性能。内核范围内的函数不需要注解(默认 C# 函数),并且可以作用于值类型。所有内核(包括共享内存和原子操作等硬件特性)都可以使用集成的多线程 CPU 加速器在 CPU 上执行和调试。
165+
166+
3、[以太坊.NET库](https://github.com/Nethereum/Nethereum)
167+
168+
Nethereum 是 .NET 的以太坊集成库,简化了与公共或许可的以太坊节点(如 Geth、Parity 或 Quorum)的访问和智能合约交互。
169+
170+
4、[币安.NET客户端库](https://github.com/JKorf/Binance.Net)
171+
172+
![image](https://github.com/DotNETWeekly-io/DotNetWeekly/assets/11272110/d5bc7acd-a0b8-446b-90b9-abc9b5e4bb8d)
173+
174+
Binance.Net 是一个强类型的客户端库,用于访问 Binance 的 REST 和 Websocket API。所有数据都映射到可读的模型和枚举值。其他功能包括实现客户端订单簿维护、与其他交易所客户端库的轻松集成等。

0 commit comments

Comments
 (0)