There is a method that receives a ValueTuple and returns it after modifying it. In this case, can I specify the field name of the ValueTuple in the method parameter?
private static void Operation()
{
var tuple = (X: 10, Y: 20);
var changeTuple = ChangeTuple(tuple);
}
private static ValueTuple<int, int> ChangeTuple(ValueTuple<int, int> tuple)
{
tuple.Item1 = 100; // ex) tuple.X = 100;
tuple.Item2 = 200; // ex) tuple.Y = 200;
return tuple;
}
Yes, you can simply replace
ValueTuple<int, int>to(int X, int Y):For reference: naming tuple's fields
Or you can use deconstruction:
Please note that in both cases you are not modifying the original
ValueTuplerather create a new one:ValueTupleis astruct, so it is passed by valueValueTuple