Thanks for this article. I once found a bit of that syntax with switch and the when keyword. I was badly wishing there is such thing because this is handy but I didn't know it is so complete. I'm going through the codes and playing them in Visual Studio.
I have questions I note as I go so there may be one or more.
Variable Patterns :
There is apparently a small error in the article because the output gives "Hi" alone. Which makes sense to me when I read the code.
_ when greetWithName == false => $"Hi", applies.
Format a string
Modified the code so that phone is null.
Does not seem to work as expected and goes to the 1st pattern.
Any Idea why?
Thanks for the fixes.
Tried them and they work.
I must admit that when reading the code this or looked legit.
But when you go back to boolean it makes sense.
TelephoneNumber is null TelephoneNumber not null → False → 0 TelephoneNumber not "" → True → 1
0 or 1 is 1 so it executes the line.
0 and 1 is 0 so it filters accordingly.
Regards.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello.
Thanks for this article. I once found a bit of that syntax with
switch
and thewhen
keyword. I was badly wishing there is such thing because this is handy but I didn't know it is so complete. I'm going through the codes and playing them in Visual Studio.I have questions I note as I go so there may be one or more.
Variable Patterns :
There is apparently a small error in the article because the output gives "Hi" alone. Which makes sense to me when I read the code.
_ when greetWithName == false => $"Hi",
applies.Format a string
Modified the code so that phone is
null
.Does not seem to work as expected and goes to the 1st pattern.
Any Idea why?
Regards.
Thanks! I think you found some syntax mistakes in the snippets, and again thanks for pointing them out.
Variable pattern should be:
Format a string should use
and
instead ofor
:Thanks for the fixes.
Tried them and they work.
I must admit that when reading the code this or looked legit.
But when you go back to boolean it makes sense.
TelephoneNumber
isnull
TelephoneNumber not null
→ False → 0TelephoneNumber not ""
→ True → 10 or 1 is 1 so it executes the line.
0 and 1 is 0 so it filters accordingly.
Regards.