ReSharper 2024.1 Help

Code inspection: Merge null/pattern checks into complex pattern

This inspection suggests using list pattern syntax introduced in C# 11.

Before the introduction of this syntax, it was generally necessary to check the length of the collection and then use indexer access expressions to check the items in the collection. This inspection identifies such checks in your code and suggests replacing them with more concise list pattern matching.

static void Main(string[] args) { if (args is ["--help", _] && args[1] is var topic) { Console.WriteLine($"Help on topic '{topic}':"); } }
static void Main(string[] args) { if (args is ["--help", var topic]) { Console.WriteLine($"Help on topic '{topic}':"); } }
Last modified: 08 May 2024