Tuesday, March 15, 2011

C# 4.0 Features -- Tuple Type

It is very straightforward, I just write some sample code below:

using System;


namespace TupleExample
{
class Program
{
static void Main(string[] args)
{
Tuple< int, string, string[]> tuple1=
new Tuple< int, string, string[]>
(5,"test",new string[3]{"test1","test2","test3"});

//Console.WriteLine(tuple1.Item1.ToString());

var tuple2 = Tuple.Create("test", new Tuple< int,int,string>(3, 2, "test"));

//Console.WriteLine(tuple2.GetType());

var tuple3 = Tuple.Create(Tuple.Create("Test", 1), 3);

//Console.WriteLine(tuple3.Item1.Item2.ToString());
}
}
}

No comments: