ReSharper suggests changing pattern matching code to object pattern

Viewed 1070

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 Answers

{} 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.

Related