Last Updated : 11 Jul, 2025
ValueTuple <T1, T2, T3, T4, T5> struct in C# is part of the System namespace and is used to create a tuple that stores quintuple or 5-ValueTuple. It offers a more lightweight, value-type tuple compared to the older Tuple class and provides better performance and memory management. The ValueTuple <T1, T2, T3, T4, T5> struct is a value type and mutable means the value of its elements can be modified.
ConstructorFieldsinstance.ValueTuple<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5)
The constructor for ValueTuple <T1, T2, T3, T4, T5> initializes the tuple with fvalues. It is not a property, it is a field that can be accessed by ValueTuple<ElementNumber>
Example: Demonstration of access to the ValueTuple<T1, T2, T3, T4, T5> element in C#.
C#
// Accessing the elements of
// ValueTuple<T1, T2, T3, T4, T5>
using System;
class Geeks
{
static public void Main()
{
// Creating a value tuple
// Using Create method
var lib = ValueTuple.Create(3456, "The Guide",
"R. K. Narayan", 1958, "Philosophical novel");
// Display the element of the given value tuple
Console.WriteLine("Book Details: ");
Console.WriteLine("Book Id: {0}", lib.Item1);
Console.WriteLine("Book Name: {0}", lib.Item2);
Console.WriteLine("Author Name: {0}", lib.Item3);
Console.WriteLine("Publication date: {0}", lib.Item4);
Console.WriteLine("Gener: {0}", lib.Item5);
}
}
Book Details: Book Id: 3456 Book Name: The Guide Author Name: R. K. Narayan Publication date: 1958 Gener: Philosophical novel
Explanation: In the above example create a ValueTuple with five elements of different types and print each element by field Item<elementNumber>.
MethodsMethod
Description
CompareTo(ValueTuple)
It compares the current ValueTuple<T1> instance to a specified ValueTuple<T1> instance.
Equals(Object)
It returns a value that indicates whether the current ValueTuple<T1> instance equals a specified object.
Equals(ValueTuple<T1>)
It returns a value that indicates whether the current ValueTuple<T1> instance equals a specified ValueTuple<T1> instance.
GetHashCode()
It calculates the hash code for the current ValueTuple<T1> instance.
ToString()
It returns a string that represents the value of this ValueTuple<T1> instance.
Example of Equals() Method in ValueTuple C#
// check if two value
// tuples are equal or not
using System;
class Geeks
{
static public void Main()
{
// Creating 5-ValueTuple
// using Create method
var T1 = ValueTuple.Create(1, 2, 3, 4, 5);
var T2 = ValueTuple.Create(1, 2, 3, 4, 5);
// Check if both the value
// tuples are equal or not
if (T1.Equals(T2))
{
Console.WriteLine("Tuples Matched...!!");
}
else
{
Console.WriteLine("Tuples Not Matched...!!");
}
}
}
Tuples Matched...!!Key Features
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4