That is, I\'d like to have a tuple of values.
The use case on my mind:
Dictionary, object>
or
<
Aye, there's System.Web.UI.Pair and System.Web.UI.Triplet (which has an overloaded creator for Pair-type behaviour!)
Fast-forward to 2010, .NET 4.0 now supports n-tuples of arbitrary n. These tuples implement structural equality and comparison as expected.
One simple solution has no been mentioned yet. You can also just use a List<T>
. It's built in, efficient and easy to use. Granted, it looks a bit weird at first, but it does its job perfectly, especially for a larger count of elements.
There are not built-in classes for that. You can use KeyValuePair or roll out your own implementation.
You could use System.Collections.Generic.KeyValuePair as your Pair implementation.
Or you could just implement your own, they aren't hard:
public class Triple<T, U, V>
{
public T First {get;set;}
public U Second {get;set;}
public V Third {get;set;}
}
Of course, you may someday run into a problem that Triple(string, int, int) is not compatible with Triple(int, int, string). Maybe go with System.Xml.Linq.XElement instead.
There aren't built ins, but a Pair<T,R> class is trivial to create.