Rank: Administration Groups: Administration
Joined: 4/5/2009 Posts: 7
|
The Tuple type in the C# programming language provides a unified type and syntax for creating an object with a variety of typed fields. Tuple type is a class and therefore will be allocated in a separate location on the managed heap in memory. However, once you create the Tuple, you cannot change the values of its fields; this restriction makes the Tuple more like a struct. In the following example, we create a three-item tuple using the special constructor syntax and then read the Item1, Item2, and Item3 properties; we do not modify them.
// Create three-item tuple. Tuple<int, string, bool> tuple = new Tuple<int, string, bool>(1, "cat", true); // Access tuple properties. if (tuple.Item1 == 1) { Console.WriteLine(tuple.Item1); } if (tuple.Item2 == "dog") { Console.WriteLine(tuple.Item2); } if (tuple.Item3) { Console.WriteLine(tuple.Item3); }
|