Last active
August 26, 2021 07:11
-
-
Save ankitvijay/e3a3d36b957ea3e4171c9c5c2da7153f to your computer and use it in GitHub Desktop.
Switch Expression Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
Console.WriteLine("GetBoolean 1:" + (GetBoolean1("Nah") == null)); | |
Console.WriteLine("GetBoolean 2:" + (GetBoolean2("Nah") == null)); | |
static Boolean? GetBoolean2(string boolString) | |
{ | |
return boolString switch | |
{ | |
"Yes" => Boolean.Yes, | |
"No" => Boolean.No, | |
_ => default | |
}; | |
} | |
static Boolean? GetBoolean1(string boolString) | |
{ | |
switch (boolString) | |
{ | |
case "Yes": | |
return Boolean.Yes; | |
case "No": | |
return Boolean.No; | |
default: | |
return default; | |
} | |
} | |
enum Boolean | |
{ | |
Yes, | |
No | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment