Tuple in C#
Tuple is a Data structured in C#
A tuple is a data structure that has a specific number and sequence of elements. 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<T1, T2, T3, T4, T5, T6, T7, TRest> object.
Tuples are commonly used in four ways:
To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record.
To provide easy access to, and manipulation of, a data set.
To return multiple values from a method without using out parameters (in C#) or ByRef parameters (in Visual Basic).
To pass multiple values to a method through a single parameter. For example, the Thread.Start(Object) method has a single parameter that lets you supply one value to the method that the thread executes at startup time. If you supply a Tuple<T1, T2, T3> object as the method argument, you can supply the thread’s startup routine with three items of data.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tuple_Example
{
class Program
{
static void Main(string[] args)
{
var TupleExamples = new Tuple < int,string,string,int>(1,"One","Two",3);
Console.WriteLine("{0}",TupleExamples.Item1);
Console.WriteLine("{0}", TupleExamples.Item2);
Console.WriteLine("{0}", TupleExamples.Item4);
Console.ReadLine();
}
}
}
Tuple is a Data structured in C#
A tuple is a data structure that has a specific number and sequence of elements. 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<T1, T2, T3, T4, T5, T6, T7, TRest> object.
Tuples are commonly used in four ways:
To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record.
To provide easy access to, and manipulation of, a data set.
To return multiple values from a method without using out parameters (in C#) or ByRef parameters (in Visual Basic).
To pass multiple values to a method through a single parameter. For example, the Thread.Start(Object) method has a single parameter that lets you supply one value to the method that the thread executes at startup time. If you supply a Tuple<T1, T2, T3> object as the method argument, you can supply the thread’s startup routine with three items of data.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tuple_Example
{
class Program
{
static void Main(string[] args)
{
var TupleExamples = new Tuple < int,string,string,int>(1,"One","Two",3);
Console.WriteLine("{0}",TupleExamples.Item1);
Console.WriteLine("{0}", TupleExamples.Item2);
Console.WriteLine("{0}", TupleExamples.Item4);
Console.ReadLine();
}
}
}
No comments:
Post a Comment