Working with other colleagues, I found these C# syntaxes are still not well-known and used, so I thought of blogging on them.
1 – Properties Without Members
In the old days, before C# 3.0, we used to write syntax like:
But if you are not doing any special processing in your property, you can use a shorter syntax introduced in C# 3.0:
2 – The null-coalescing operator
While all of use, especially those coming from C/C++ background have used the ternary operator
?:, such as:
However, C# 2.0 introduced this new syntax:
Which does exactly the same as the previous syntax.
3 – Initialising Properties when Creating an Object
Or you can use the C# 3.0 syntax:
Probably if you are using LINQ then you have used this code several times.