Hızlı yanıt: kod örneği
Tuples are available since .NET4.0 and support generics:In previous versions you can use or a solution like the following:And use it like this:This outputs:Or even this chained pairs:That outputs:
Tuple<string, int> t = new Tuple<string, int>("Hello", 4);
System.Collections.Generic.KeyValuePair<K, V>
public class Pair<T, U> { public Pair() { } public Pair(T first, U second) { this.First = first; this.Second = second; } public T First { get; set; } public U Second { get; set; }};
Pair<String, int> pair = new Pair<String, int>("test", 2);Console.WriteLine(pair.First);Console.WriteLine(pair.Second);
test2
Pair<Pair<String, int>, bool> pair = new Pair<Pair<String, int>, bool>();pair.First = new Pair<String, int>();pair.First.First = "test";pair.First.Second = 12;pair.Second = true;Console.WriteLine(pair.First.First);Console.WriteLine(pair.First.Second);Console.WriteLine(pair.Second);
test12true