Use of Tuple concepts in c#
Why we are using Tuple concepts instead of Dictionary or list?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dhirendra MisraRank #4,173 · 360 reputationPosted Jan 6, 2014, 10:34 PM EST
A Tuple has many items. Each item can have any type. The Tuple class provides a unified syntax for creating objects with typed fields. Once created, the fields in the Tuple cannot be mutated. This makes the Tuple similar to a value type.
An example of a tuple is a data structure with three elements (known as a 3-tuple or triple) that is used to store an identifier such as a person's name in the first element, a year in the second element, and the person's income for that year in the third element. The .NET Framework directly supports tuples with one to seven elements. In addition, you can create tuples of eight or more elements by nesting tuple objects in the Rest property of a Tuple
Tuples are commonly used in four ways:
Examples to create tuple:
// Create a 7-tuple.
var population = new Tuple<string, int, int, int, int, int, int>( "New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278); // Display the first and last elements.
Console.WriteLine("Population of {0} in 2000: {1:N0}", population.Item1, population.Item7);
Using Create Method:
// Create a 7-tuple.
var population = Tuple.Create("New York", 7891957, 7781984, 7894862, 7071639, 7322564, 8008278); // Display the first and last elements.
Console.WriteLine("Population of {0} in 2000: {1:N0}", population.Item1, population.Item7);
Performance compared with keyValuePair:http://www.dotnetperls.com/tuple-keyvaluepair
VulpesRank #55 · 29.2K reputationPosted Jan 7, 2014, 4:10 AM EST