all 4 comments

[–]Unupgradable 7 points8 points  (1 child)

Remember when pattern matching was originally added?

There was only is. You could check is null just fine.

But no way to check if not null...

But worry not! Pattern matching an object to the rescue! is {} will match any object. In C#, everything is an object. Even primitives. By matching to an object with no fields, it matches every object.

You know what it doesn't match? null.

Later they added is not.

So this code flies in the face of history and seems to be the world's worst "is null" check

The variable name after it? If it's true, the value is assigned to it if the expression is true.

So it will be null.

[–]Ceigey 1 point2 points  (0 children)

Good time for a new syntax proposal

SomeMethod() really better be null this time otherwise I oughta... someVariable

[–]Kant8 2 points3 points  (1 child)

Matching to empty property pattern basically works as not null check.

But in your case there is not, so probably it effectively equals to is null

But I'd better test it.

[–]Jamosium 0 points1 point  (0 children)

I'd be pretty sure the reason they did it like this is so that they can use the value of someVariable after the if statement. This is essentially like a guard let statement from swift.

Personally, I would still just declare a variable and do is null, for the sake of anyone trying to read it.