The Tuple<T1, T2, T3, T4, T5, T6> class is used to create a 6-tuple or sextuple. It represents a tuple which contains the six elements in it. You can instantiate a Tuple<T1, T2, T3, T4, T5, T6> object by calling either the Tuple<T1, T2, T3, T4, T5, T6>(T1, T2, T3, T4, T5, T6) constructor or by the static Tuple.Create method. You can retrieve the value of the tuple’s elements by using the read-only Item1, Item2, Item3, Item4, Item5, and Item6 instance property.
Important Points:
- It implements IStructuralComparable, IStructuralEquatable, and IComparable interface.
- It defined under System namespace.
- It represent multiple data into a single data set.
- It allows us to create, manipulate, and access data set.
- It returns multiple values from a method without using out parameter.
- It allows passing multiple values to a method with the help of single parameters.
- It can also store duplicate elements.
Constructor
.tuple-class-table { border-collapse: collapse; width: 100%; } .tuple-class-table td { border: 1px solid #5fb962; text-align: left !important; padding: 8px; } .tuple-class-table th { border: 1px solid #5fb962; padding: 8px; } .tuple-class-table tr>th{ background-color: #c6ebd9; vertical-align: middle; } .tuple-class-table tr:nth-child(odd) { background-color: #ffffff; }Â
Constructor |
Description |
Tuple<T1, T2, T3, T4, T5, T6>(T1, T2, T3, T4, T5, T6) |
Initializes a new instance of the Tuple<T1, T2, T3, T4, T5, T6> class. |
Property
Property |
Description |
Item1 |
Gets the value of the Tuple<T1, T2, T3, T4, T5, T6> object’s first component. |
Item2 |
Gets the value of the current Tuple<T1, T2, T3, T4, T5, T6> object’s second component. |
Item3 |
Gets the value of the current Tuple<T1, T2, T3, T4, T5, T6> object’s third component. |
Item4 |
Gets the value of the current Tuple<T1, T2, T3, T4, T5, T6> object’s fourth component. |
Item5 |
Gets the value of the current Tuple<T1, T2, T3, T4, T5, T6> object’s fifth component. |
Item6 |
Gets the value of the current Tuple<T1, T2, T3, T4, T5, T6> object’s sixth component. |
Example:
csharp
using System;
class GFG {
static public void Main () {
Tuple< int , int , int , string , int , string >mytuple = new Tuple< int ,
int , int , string , int , string >(79, 34, 67, "Geeks" ,
44, "GeeksforGeeks" );
Console.WriteLine( "Value of the First Component: " + mytuple.Item1);
Console.WriteLine( "Value of the Second Component: " + mytuple.Item2);
Console.WriteLine( "Value of the Third Component: " + mytuple.Item3);
Console.WriteLine( "Value of the Fourth Component: " + mytuple.Item4);
Console.WriteLine( "Value of the Fifth Component: " + mytuple.Item5);
Console.WriteLine( "Value of the Sixth Component: " + mytuple.Item6);
}
}
|
Output:
Value of the First Component: 79
Value of the Second Component: 34
Value of the Third Component: 67
Value of the Fourth Component: Geeks
Value of the Fifth Component: 44
Value of the Sixth Component: GeeksforGeeks
Methods
Method |
Description |
Equals(Object) |
Returns a value that indicates whether the current Tuple<T1, T2, T3, T4, T5, T6> object is equal to a specified object. |
GetHashCode() |
Returns the hash code for the current Tuple<T1, T2, T3, T4, T5, T6> object. |
GetType() |
Gets the Type of the current instance. |
MemberwiseClone() |
Creates a shallow copy of the current Object. |
ToString() |
Returns a string that represents the value of this Tuple<T1, T2, T3, T4, T5, T6> instance. |
Example:
CSharp
using System;
class GFG {
static public void Main()
{
Tuple< int , int , int , int , int , int > mytuple1 = new Tuple< int ,
int , int , int , int , int >(20, 40, 90, 89, 33, 66);
Tuple< int , int , int , int , int , int > mytuple2 = new Tuple< int ,
int , int , int , int , int >(20, 40, 90, 89, 33, 66);
if (mytuple1.Equals(mytuple2))
{
Console.WriteLine( "Tuple Matched." );
}
else {
Console.WriteLine( "Tuple not Matched." );
}
}
}
|
Reference:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
29 Aug, 2021
Like Article
Save Article