Here we are, friends: our last post in our C# 9 deep dive series. We’ve discussed a lot of topics, so I thought it’d be fun to bundle all we’ve learned into a single post. (You can think of this as a CliffsNotes of the 10,000 or so words I’ve written about C# 9 so far.)
Since C# was first introduced, developers have complained about the lack of a range operator in switch constructs. This made switches far less useful in C# than they were in VB. As part of the pattern-matching enhancements for C# 9, this limitation has been addressed.
We’ve been quite busy, my friends. In this C# 9 deep dive series, we’ve looked at init-only features, records, pattern matching, and then top-level programs. To complete this series (before showing off everything in a single app), we’ll discuss the last two items featured in the Build 2020 announcement: target typing and covariant returns. These are not related, but I’ve decided to bundle these in a single blog post. This is the fifth post in a six-post series on C# 9 features in-depth...
In my last blog in this series, I talked about the AllowNull attribute. This post shows its converse, DisallowNull. As with all the attributes relating to nullable references, the goal is to improve expressiveness, enabling the compiler to report more nullable-related problems without producing spurious warnings.
This article is part of an article series about the IO container in C#. In the previous articles, you've seen how a type like IO
While working on an issue in Codespaces, I figured this would be a good case to implement some regex. Each time I work with regex I need to figure out how it works again, but also each time I am impressed with how powerful it is. And actually, this time I learned something new: regex named groups. Regex has the ability to name each matched group which is very easy to subsequently use in C# code. In this post, I will tell you how to do exactly that.
本文说的随机文件读写的随机的反义词是顺序，这里的随机文件读写对应顺序文件读写。表示文件可以不按照顺序进行读写。进行文件读写的时候，基本上读是几乎不存在问题的，而写的话就稍微坑了一点，在 dotnet 里面默认没有提供 RandomAccessStream 类，这个 RandomAccessStream 类仅在 UWP 中可以使用。如果在不引用 UWP 的 WPF 里面，或者在 ASP.NET Core 以及 Xamarin 里面，也可以通过 FileStream 的 Seek 方法做到进行随机的读写...
In the June 24th C# Language Design Meeting, Microsoft made a subtle change to the parameter null checking syntax. By changing it from Type parameterName! to Type parameterName!! they effectively introduced a new ‘null check operator’.
委托与事件在C#1.0的时候就有了，随着C#版本的不断更新，有些写法和功能也在不断改变。本文温故一下这些改变，以及在NET Core中关于事件的一点改变。一、C#1.0 从委托开始1. 基本方式什么是委托，就不说概念了，用例子说话。某HR说他需要招聘一个6年 .NET5 研发经验的“高级”工程师，他想找人（委托）别人把这条招聘消息发出去。这样的HR很多，所以大家定义了一个通用的发消息规则：public delegate string SendDelegate(string message);这就像一个接口的方法，没有实际的实现代码，只是定义了这个方法有一个string的参数和返回值。所有想发招...
A few weeks ago, we took a quick tour of some upcoming C# 9 features that will make your development life easier. We dipped our toes in the water. But now it’s time to dig a little deeper.I’m starting a new series over the next several weeks, that will showcase all of the announced featuresincrement...
Sometimes you run across things you should probably never do in real life but are possible in your development environment. Having more than one "Main()" method in an application is one of those things in the .NET world.
So far in this sub-series on attributes for getting better results from C# 8's nullable references feature I've described the AllowNull and DisallowNull attributes. Now it's NotNull's turn. As with all of these attributes, this enables us to describe our intent in more detail so that the compiler can find more null-related programming errors without producing spurious warnings. This particular post is concerned with a scenario where the successful execution of a method implies that we can now be certain that something isn't null, and we'd like the compiler to know that.
In this article, we’re going to tackle the popular question among many developers, and that’s “What’s the difference between string and String” and “When should I use string, and when should I use String” in my applications. Both of these versions exist for a reason, so let’s see what they are and if they’re indeed that important.
Pattern matching has been introduced in C# 6 and has well evolved since. The latest improvement was pretty interesting on C# 8 which has been released last year. If you missed pattern matching improvements on C# 8 , here is a nice article from Miguel Bernard (@MiguelBernard88): https://blog.miguelbernard.com/pattern-matching-in-csharp/. If you have missed all new features in C# 8, you can read also his great serie here: https://blog.miguelbernard.com/csharp-8-0-new-features/. In this article I will show you all the great new features of pattern matching.