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:

4 lines

Into this:

1 line

Set Booleans depending on a condition:

4 lines

Into this:

1 line

Null-checking a variable:

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.