Favour Boolean assignment via expressions in C# rather than if/else blocks

Where applicable favour Boolean assignment via expressions rather than if/else blocks. The first example below is still so common but the 2nd and 3rd examples require much less code without sacrificing readability.

Note… Visual Studio has a nice refactor to help converting relevant if/else blocks to an expression.

Leave a Reply

Your email address will not be published. Required fields are marked *