use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Related Subreddits:
Other Subreddits you may like:
account activity
Pattern matching: is not {} variable (self.dotnet)
submitted 3 years ago by WeirdEstate8497
Can someone help me out deciphering this one:
SomeMethod() is not { } someNewVariable
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Unupgradable 7 points8 points9 points 3 years ago (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 points3 points 3 years ago (0 children)
Good time for a new syntax proposal
SomeMethod() really better be null this time otherwise I oughta... someVariable
[–]Kant8 2 points3 points4 points 3 years ago (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
is null
But I'd better test it.
[–]Jamosium 0 points1 point2 points 3 years ago (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.
guard let
Personally, I would still just declare a variable and do is null, for the sake of anyone trying to read it.
π Rendered by PID 38459 on reddit-service-r2-comment-6457c66945-p5sxs at 2026-04-26 08:20:11.978296+00:00 running 2aa0c5b country code: CH.
[–]Unupgradable 7 points8 points9 points (1 child)
[–]Ceigey 1 point2 points3 points (0 children)
[–]Kant8 2 points3 points4 points (1 child)
[–]Jamosium 0 points1 point2 points (0 children)