ReSharper suggests changing pattern matching code to object pattern

邮差的信 提交于 2021-01-02 06:27:47

问题


ReSharper suggests changing the following code:

if (MyString is string myString)
{
    //...
}

to object pattern:

if (MyString is { } myString)
{
    //...
}

It says:

The source expression is always of pattern's type, matches on all non-null values.

I have never seen this syntax before, and I cannot find any documentation of it. What is it and what does it do?


回答1:


{} stand for not null, but not invokes != operator, so it's safe like is null operator which not invoke == operator.

There is lack of information about it. I found thread on github about it. This is a preview feature for now i think.



来源:https://stackoverflow.com/questions/58427535/resharper-suggests-changing-pattern-matching-code-to-object-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!