ReSharper 2025.1 Help

Code inspection: Prefer explicitly provided tuple component name

In modern C#, tuples allow you to provide explicit names for each element when declaring them. For example, (int First, int Second) clearly defines meaningful names for the tuple elements. However, when one fails to use these names and instead accesses tuple components through default generated names like Item1, Item2, it reduces code clarity.

In the example below, the tuple parameter t0 explicitly declares the names First and Second. However, inside the constructor, the code uses Item2 to access the second element of the tuple rather than its explicit name Second.

Using default name Item2 instead of the explicit name Second makes it harder to understand the meaning or context of the tuple component.

public class TupleSample { TupleSample((int First, int Second) t0) { var t1 = (t0.First, t0.Item2); } }
public class TupleSample { TupleSample((int First, int Second) t0) { var t1 = (t0.First, t0.Second); } }

To resolve this problem, provide explicit component names for tuples where applicable. This makes the code more self-documenting and reduces potential confusion with Item-style default names.

Last modified: 25 March 2025