Member-only story
CODEX
4 Easy C# Programming Tricks in 2022
Improve your C# skills with these beginner-friendly coding tricks.
3 min readFeb 16, 2021
Writing beautiful code is essential for any software developer. This article shows four easy C# programming “tricks” you can use to write more professional code.
1. One-Line If-Else Statements
In C# there is a conditional operator that lets you convert your if-else statements to one-liner expressions.
As an example, you can replace this if-else expression:
With a more concise one-liner expression:
message = age > 18 ? "You are an adult." : "You are not an adult.";Console.WriteLine(message);
Output:
You are not an adult.
Generally, the structure of a conditional operator is:
condition ? true_expression : false_expression;