Last active
July 14, 2023 14:52
-
-
Save a-patel/94fbdea046a6a898184949cd138b0d0e to your computer and use it in GitHub Desktop.
C#.NET - Ternary Conditional Operator(?:) Example
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
/* Example-1 */ | |
// Without ternary conditional operator | |
int age = 25; | |
string type; | |
if (age >= 18) | |
{ | |
type = "Adult"; | |
} | |
else | |
{ | |
type = "Child"; | |
} | |
// With ternary conditional operator | |
string type = age >= 18 ? "Adult" : "Child"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment