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
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
No, Unity does not support Tuples. Maybe when Unity upgrades its Mono version to support features that came in .NET Framework 4.
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
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.
– ExcursionistThese 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.
© 2022 - 2024 — McMap. All rights reserved.
Really!!?!? Just a continuous disappointment this.
– Algicide