Use C# 10 Global Usings to make namespaces available to all files in a project

Global Usings in C# 10 allow us to declare a namespace as being available to all files in a project so we don’t need a using statement for it in each file which needs it. Ideally we’d put these global usings in a separate file. This will reduce so called ‘vertical waste’ which is nice.  … Continue reading Use C# 10 Global Usings to make namespaces available to all files in a project

Use file-level namespaces in C# 10 to reduce vertical nesting

In C# 9 we saw how top-level statements can help us reduce ‘wasted’ vertical space… BUT… reducing ‘wasted’ horizontal space and in particular nesting levels is much more valuable IMHO and in C# 10 (released November 2021) we have file-level namespaces to help with this. File-level namespaces are definitely one of my favourite features from … Continue reading Use file-level namespaces in C# 10 to reduce vertical nesting

Consider using named arguments in C# to increase readability of method calls

By using named arguments in C# we don’t have to match the ordering of parameter lists of called methods. Instead the matching parameter for each argument can be specified by parameter name. I never use these to change the position of arguments passed in as I find that can confuse other developers but I often use … Continue reading Consider using named arguments in C# to increase readability of method calls

C# – How to generate random password

This article delivers proposal of algorithm to generate random passwords or actually random strings which are generated in safe manner and can be used as passwords, discount codes etc. Also, it is configurable, so that you can easily define expected length of string, pool of available characters or minimal number of occurrences of particular elements. … Continue reading C# – How to generate random password

C# – How to get unique items from list

The easiest way of getting unique items from list is LINQ’s Distinct() method. In this article you’ll see how to use it with both built-in types (like collection of integers) and custom types (like collection of complex type objects). Get unique values from collection of integers Let’s start with creating example list of items where … Continue reading C# – How to get unique items from list