Ternary and Switch Expressions
cond ? a : b picks between values. A switch expression maps patterns to results.
Example
int n = 3;
string s = n % 2 == 0 ? "even" : "odd";
string name = n switch { 1 => "one", 2 => "two", _ => "many" };
Console.WriteLine($"{s} {name}");Exercise
Default arm.
_ "many"
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.