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.
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.