Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create named reference-type tuples?

The following line creates a named ValueTuple:

var tuple = (a:1, b:2, c:3, d:4, e:5, f:6);  

Value types can not be passed around efficiently. Does C#7 offer a way to create named tuples of the Tuple type?

like image 351
brandon Avatar asked Jun 11 '17 21:06

brandon


1 Answers

If you mean if there's a way to attach other names to the properties of System.Tuple<...> instances, no there isn't.

Depending on why you want it, you might get around it by converting System.Tuple<...> instances to System.ValueTuple<...> instances using the ToValueTuple overloads in TupleExtensions and back using the ToTuple overloads.

If you don't really need the tuples, you can deconstruct them into discrete variables using the Deconstruct overloads or the var (v1, .., vn) = tuple deconstruction syntax.

like image 154
Paulo Morgado Avatar answered Sep 19 '22 17:09

Paulo Morgado