# Tuples in Unity, or how to store two pieces of data in as a single entity in a sortable list? [closed]

I'm currently trying to figure out a way to store a Vector 2 and an int together as an item in a list, in order to be able to sort a list of destinations by priority (indicated by the int stored with the Vector 2). I want to initialize the list of tuples with nothing in it, add items to it, and have it persist once it becomes empty again.

I would have thought Tuples would be perfect for this, but I cannot find a way to get this working in Unity with C#, and when I try the following:

List<Tuple<Vector2, int>> targetList;


I get the following error:

C# the type or namespace name "Tuple" could not be found.


I am using System.Collections.Generic, and I can use Tuples elsewhere, it's only when trying to use them in a list this way that I get the error.

Something important of note is that the list would be empty the majority of the time, as items will be added and removed from the list at a different rate.

I have failed to find a working example of something like this while trying to problem solve this.

• As explained in the C# documentation, Tuple and ValueTuple are part of the System namespace, not System.Collections.Generic. But you can use the syntax List<(Vector2, int)> targetList; instead of explicitly constructing a ValueTuple by name. To work with Unity serialization and the inspector, you might want to consider making a [System.Serializable] public struct with these values instead. Then you can implement IComparable on that type to get sorting out of the box. Jan 13 at 23:03