Why is TRest in Tuple <T1 ... TRest> unlimited?
In a tuple, if you have more than 7 elements, you can provide the 8th element, which is another tuple, and define up to 7 elements, and then another tuple as the eighth, and then down the line. However, at compile time there is no restriction on the 8th element. For example, this is legal code for the compiler:
var tuple = new Tuple<int, int, int, int, int, int, int, double>
(1, 1, 1, 1, 1, 1, 1, 1d);
Although the intellisense documentation states that TRest should be a tuple. You do not get any errors when writing or creating code, this does not appear until execution as an ArgumentException.
You can roughly implement Tuple in a few minutes, complete with an 8th element limited by Tuple. I'm just wondering why this has been discontinued with the current implementation? Perhaps this is a direct compatibility issue in which they can add additional elements with hypothetical C # 5?
Short version of rough implementation
interface IMyTuple { }
class MyTuple<T1> : IMyTuple
{
public T1 Item1 { get; private set; }
public MyTuple(T1 item1) { Item1 = item1; }
}
class MyTuple<T1, T2> : MyTuple<T1>
{
public T2 Item2 { get; private set; }
public MyTuple(T1 item1, T2 item2) : base(item1) { Item2 = item2; }
}
class MyTuple<T1, T2, TRest> : MyTuple<T1, T2> where TRest : IMyTuple
{
public TRest Rest { get; private set; }
public MyTuple(T1 item1, T2 item2, TRest rest)
: base(item1, item2)
{
Rest = rest;
}
}
...
var mytuple = new MyTuple<int, int, MyTuple<int>>
(1, 1, new MyTuple<int>(1)); // legal
var mytuple2 = new MyTuple<int, int, int>(1, 2, 3); // illegal at compile time