Here are my top basic 12 C# utility Tips & Tricks I usually use when programming daily:

My most used tips and tricks that I use daily when programming in C# and dotnet.

  1. Null-Conditional Operator including chaining:

You can also provide a fallback or default value:

2. Printing of a variable, type or member without hard coding:

3. Print the current method name dynamically:

4. Use of Interpolated strings that can be useful for email templates

5. Join an array of characters to a single string:

6. Date formatting comes in super handy, here’s a list of snippets from the book [1]:

7. Copying arrays — both shallow and deep:

8. Get all members values of an enum:

Enum equality check:

9. Convert a List to a HashSet:

Checking if an element is present in a HashSet is faster than in a List (0(1) vs 0(n)) esp. with large data sets.

10. Use of Singleton constructor pattern:

Singleton can be useful when managing access to a resource that is shared across the application and might be costly to have multiple e.g. database connection pool.

11. Simple Object initializers with non-default constructor:

Instead of creating a new class and assigning the properties individually, you can use an initializer.

12. Named Arguments:

With such arguments, the order you pass them is not essential.

Another popular concept is the use of Extension Methods, which enable you to extend the behaviour of existing classes without modifying the source code or requiring special permissions.



Senior Software Developer, Writer, Amateur Photographer, Reader

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