写 LINQ 的时候,别习惯性 .ToList() 了。停下来想一想:“我真需要它能增删吗?” 这两行代码看起来差不多,作用也都是立刻执行查询,并把结果存下来。但它们其实有本质区别,适用的场景也不一样。 别急着抄代码,先搞清楚该用哪个,才能写出又快又稳的程序。 用 .ToList():如果你拿到结果后,还想增删元素(比如 Add、Remove、Insert)。 用 .ToArray():如果你只是 ...
模式匹配是 C# 8+ 的核心特性,但很多模型还是习惯写 if (x is Foo f && f.Bar > 0) 这样的长链。switch 表达式更简洁、更易读,而且 ...
A monthly overview of things you need to know as an architect or aspiring architect. Unlock the full InfoQ experience by logging in! Stay updated with your favorite authors and topics, engage with ...
Check Professional C# and .NET - 2021 Edition for the code samples of the next edition of the book. Code samples for the Wrox Press book Professional C# 7 and .NET ...
As modern .NET applications grow increasingly reliant on concurrency to deliver responsive, scalable experiences, mastering asynchronous and parallel programming has become essential for every serious ...
Structured concurrency offers a more organized and more intuitive way of managing the lifetimes of asynchronous tasks. Here’s how to take advantage of it in C#. Modern programming languages such as C# ...
There's a lot of confusion about async/await, Task/TPL and asynchronous and parallel programming in general, so Jeremy Clark is on a mission to inform developers on how to use everything properly.
在本文中,我们将讨论ASP.NET Core中的新路由。我们将了解什么是接口(endpoints)路由,它是如何工作的,它在哪里使用,以及如何创建自己的路由。 名词定义:端点,即我们访问的接口或者叫API,有些地方叫EndPoint或者叫接口,其实源头的称呼应该叫端点会更贴切一些 ...