✅ Simple question
I have a code which
that prints okay but out of curiosity, can I do this with symbols? like
6 Replies
Well, can you do it?
Have you tried? Did it work?
The first code block is using pattern matching, it's a specific feature where you can use
or
to test against for different matches. The second code block uses the binary conditional logic operators which only work on booleans (true
or false
).Only works with bools and it so happens the logical and equality operators return bool. Pattern matching helps make it more readable and can warn you if the expression is contradictory or will always be true. As a side effect, pattern matching only works when comparing to constants.
The code you've shown compiles into plain
||
's. Take a look at sharplab decompile:
https://sharplab.io/#v2:CYLg1APgAgTADAWAFCwIzOQNwIYCcAE2+AvPgETYB2AnmQNwZICWAZvgBRFMDO5TALgFMAtqjL4A9gTICRMcVPJVaASmQBvZPm34oqAJzsyEgNbZVDJAF8gASharpLab
C#/VB/F# compiler playground.
Thanks for best explain.
$close
Use the
/close
command to mark a forum thread as answered