-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] var pattern in IF statement while making null check #2102
Comments
dup of #1944 |
With C# 8, you can do this with the if(Long.Named.Method.Chain.Or.Static.Etc.Value is {} x) … EDIT Ah, I see @ufcpp already posted a code example showing this in action 😃 |
Thanks for the info guys. I could not realized something similar was proposed before. 😊 |
Can't you already do the following with C#7 (sure, a bit more verbose)? If you know the type, then it's practically the same (but sure, not |
@pinkfloydx33 Yeah, the first one is sort of verbose. In fact, the second is better and easy to use for now. We will have this problem solved totally with C# 8 as in @DavidArno's post. |
Please close, then. |
Wouldn't it be better if we can create a variable inside IF statement if checked value is not null, like we have in type checking with "is";
To make it clear;
Otherwise, It has to be a variable defined before the IF statement in order not to write long-character variable over and over again. Like this;
The text was updated successfully, but these errors were encountered: