concept element name in category c#

appears as: element names, n element name, element names
C# in Depth, Fourth Edition

This is an excerpt from Manning's book C# in Depth, Fourth Edition.

Now that you’ve seen the basics of how tuples work, let’s dive a bit deeper. In the next section, we’ll mostly be considering conversions, but we’ll also look at where element names are important and where they’re not.

Effectively, the C# compiler ignores the names for the purposes of mapping C# tuple types to CLR ValueTuple<...> types. Although (int, int) and (int x, int y) are distinct types from a C# language perspective, they both map onto ValueTuple <int, int>. The compiler then maps any uses of element names to the relevant ItemN name. Figure 11.5 shows the effective translation of C# with a tuple literal into C#, which refers only to the CLR types.

Figure 11.5. Compiler translation of tuple type handling into use of ValueTuple

Notice that the lower half of figure 11.5 has lost the names. For local variables like this, they’re used only at compile time. The only trace of them at execution time would be in the PDB file created to give the debugger more information. What about element names that are visible outside the relatively small context of a method?

The dynamic binder doesn’t know about element names

Remember that element names are mostly a compile-time concern. Mix that with the way dynamic binding happens only at execution times, and I suspect you can see what’s coming. As a simple example, consider the following code: