Single Line If Statement in C#

Here is a standard if … then statement in C# followed by a single line example. Using a single line if statement will reduce the number of lines of code.

if (dayOfTheWeek == "Tuesday")
    lunchLocation = "Fuddruckers";
    lunchLocation = "Food Court";

And the same example as a single line if … then statement.

lunchLocation = (dayOfTheWeek == "Tuesday") ? "Fuddruckers" : "Food Court";

Published by


Critical MAS is the blog for Michael Allen Smith of Seattle, Washington. My interests include traditional food, fitness, economics, and web development.

2 thoughts on “Single Line If Statement in C#”

Comments are closed.