Tuyples can hold a set of differently typed elements.
Its constructors:
public class Tuple <T1>
public class Tuple <T1, T2>
public class Tuple <T1, T2, T3>
public class Tuple <T1, T2, T3, T4>
public class Tuple <T1, T2, T3, T4, T5>
public class Tuple <T1, T2, T3, T4, T5, T6>
public class Tuple <T1, T2, T3, T4, T5, T6, T7>
public class Tuple <T1, T2, T3, T4, T5, T6, T7, TRest>
Tuples has read-only properties called Item1
, Item2
, and so on.
One for each type parameter.
You can instantiate a tuple via its constructor:
using System;
class Sample
{
public static void Main()
{
var t = new Tuple<int, string>(123, "Hello");
}
}
or via the static helper method Tuple.Create
:
using System;
class Sample
{
public static void Main()
{
Tuple<int, string> t = Tuple.Create(123, "Hello");
}
}
then access the properties as follows:
using System;
class Sample
{
public static void Main()
{
var t = Tuple.Create(123, "Hello");
Console.WriteLine(t.Item1 * 2); // 246
Console.WriteLine(t.Item2.ToUpper()); // HELLO
}
}
The output:
246
HELLO
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |