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?
{}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With