Code Simplifications in C# (pt.1)

Since initially learning to program in C# many years ago, there have been many things I’ve learnt or new updates that have come out to simplify some pieces of code.

I now use these by default when I can, and wanted to list some to help anyone who perhaps didn’t know about them. So, I hope this helps someone! :)

One-line functions:

Turn this:

4 lines

Into this:

1 line

Set Booleans depending on a condition:

Turn this:

4 lines

Into this:

1 line

Null-checking a variable:

Turn this:

2 lines

Into this:

Note: This only works with some variable types, and is not always recommended as it can bypass some Unity null-checking.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.