Skip to content

Instantly share code, notes, and snippets.

@a-patel
Last active July 14, 2023 14:52
Show Gist options
  • Save a-patel/94fbdea046a6a898184949cd138b0d0e to your computer and use it in GitHub Desktop.
Save a-patel/94fbdea046a6a898184949cd138b0d0e to your computer and use it in GitHub Desktop.
C#.NET - Ternary Conditional Operator(?:) Example
/* 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