Does Unity 4 Mono support Tuples?
Asked Answered
D

4

0

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

Depository answered 6/6, 2023 at 1:47 Comment(0)
M
0

No, Unity does not support Tuples. Maybe when Unity upgrades its Mono version to support features that came in .NET Framework 4.

Maddy answered 6/6, 2023 at 1:52 Comment(1)

Really!!?!? Just a continuous disappointment this.

Algicide
E
0

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

Escarp answered 6/6, 2023 at 2:5 Comment(0)
P
0

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;
    }
}
Pigtail answered 6/6, 2023 at 2:0 Comment(1)

A tuple of two is called a Pair, so that the class would be better if it was named Pair.

Excursionist
I
0

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.

Isobar answered 30/12, 2017 at 20:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.