- Home /
Does Unity 4 Mono support Tuples?
Does the Mono that ships with Unity 4 support Tuples? Mono is 2.6, I have not found a definitive answer online. Is anyone using Tuples with Unity 4?
Thanks, -E
Answer by zharramadar · Feb 18, 2013 at 07:12 PM
No, Unity does not support Tuples. Maybe when Unity upgrades its Mono version to support features that came in .NET Framework 4.
Answer by ShawnFeatherly · Jan 26, 2014 at 02:55 AM
Doesn't seem available in the Unity 4.3 either. But you can always include your own copy of Tuple.cs: https://gist.github.com/michaelbartnett/5652076
Answer by VertexSoup · Jan 21, 2015 at 01:44 AM
Something like this may help you or use ShawnFeatherly premade classes:
public class Tuple<T1, T2>
{
public T1 First { get; private set; }
public T2 Second { get; private set; }
internal Tuple(T1 first, T2 second)
{
First = first;
Second = second;
}
}
public static class Tuple
{
public static Tuple<T1, T2> New<T1, T2>(T1 first, T2 second)
{
var tuple = new Tuple<T1, T2>(first, second);
return tuple;
}
}
A tuple of two is called a Pair, so that the class would be better if it was named Pair.
public class Tuple<T1, T2, T3>
{
public T1 First { get; private set; }
public T2 Second { get; private set; }
public T3 Third { get; private set; }
internal Tuple(T1 first, T2 second, T3 third)
{
First = first;
Second = second;
Third = third;
}
}
public static class Tuple
{
public static Tuple<T1, T2, T3> New<T1, T2, T3>(T1 first, T2 second, T3 third)
{
var tuple = new Tuple<T1, T2, T3>(first, second, third);
return tuple;
}
}
Answer by VitruvianStickFigure · Dec 30, 2017 at 08:38 PM
These are great responses; though sometimes when I'm trying to keep my project tidy, I'll work with out parameters instead. For instance:
Vector3 v = ...;
Tuple<int, int, int> c = ConvertToInts(v);
would become
Vector3 v = ...;
int x, y, z;
ConvertToInts(v, out x, out y, out z);
This obviously doesn't do everything that Tuples are around for, and you can't use it on a property; but it's helped me skirt around the problem multiple select times in the past.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Rotate Camera 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
When will Unity Support .NET 4 to the current Mono Level? 1 Answer