With the introduction of this new feature we you do not require to explicitly declare the tuple candidate names. We discussed Tuples in previous section Tuples and Deconstructions. Infer tuple names feature is an extended to the tuple values introduced in C# 7.0.
To work with this new feature, you require updated NuGet package of ValueTuple
that you’ve installed in previous section Tuple. To update the NuGet package, go to NuGet Package manager and click on Update
tab and then click update latest version
. Following screenshot provides the complete information:
Following code-snippet shows, various ways to declare the tuple:
public static void InferTupleNames(int num1, int num2) { (int, int) noNamed = (num1, num2); (int, int) IgnoredName = (A:num1, B:num2); (int a, int b) typeNamed = (num1, num2); var named = (num1, num2); var noNamedVariation = (num1, num1); var explicitNaming = (n: num1, num1); var partialnamed = (num1, 5); }
The preceding code...