Sitemap
CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

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

--

Original Image: Markus Spiske

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;

2. Default Value for Null

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Responses (4)