A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/c-sharp/c-sharp-valuetuple-8-struct/ below:

C# - ValueTuple <T1,T2,T3,T4,T5,T6,T7,TRest> Struct

C# - ValueTuple <T1,T2,T3,T4,T5,T6,T7,TRest> Struct

Last Updated : 11 Jul, 2025

<ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> struct in C# is part of the System namespace and is used to create n-ValueTuple where n = 8 or greater than 8. It offers a more lightweight, value-type tuple compared to the older Tuple class and provides better performance and memory management. The ValueTuple struct is a value type and mutable means the value of its elements can be modified. Some key features of tuples are mentioned below:

Constructor

// Initializes a new ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> instance.
ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest>(T1, T2, T3, T4, T5, T6, T7, TRest)

Fields

The constructor of the ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> struct initializes the tuple with seven values, Including the optional TRest that can represent additional elements, Accessed via fields ValueTuple<ElementNumber>.

Example:

C#
// Accessing the element of ValueTuple<T1, 
// T2, T3, T4, T5, T6, T7, TRest> 
using System; 

class Geeks
{
	static public void Main()
	{
		// Creating a value tuple using Create method 
		var lib = ValueTuple.Create(3, "C#", "Geek",
		2025, "Programming", "English", "India", 
		ValueTuple.Create("Java", "Javascript",  
        "Kotlin"));

		// Display the element of the value-tuple 
		Console.WriteLine("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);
		Console.WriteLine("Language: {0}", lib.Item6);
		Console.WriteLine("Country: {0}", lib.Item7);
		Console.WriteLine("Other Books Details: " + lib.Rest);

	}
}

Output
Details: 
Book Id: 3
Book Name: C#
Author Name: Geek
Publication date: 2025
Gener: Programming
Language: English
Country: India
Other Books Details: ((Java, Javascript, Kotlin))

Explanation: In the above example, we create a ValueTuple with seven elements and one nested valueTuple of different types and print each element by field Item<elementNumber> and nested valuetuple using ValutupleObject.Rest(Instance).

Methods

Methods

Description

CompareTo(ValueTuple)

Compares two tuples element by element and returns (0,1,-1) value based on their order.

Equals(Object)

Check the Object equal to the current ValueTuple instance, return true if equals else return false

Equals(ValueTuple)

Checks if two ValueTuple instances are equal by comparing their elements, return true if equals else return false

GetHashCode()

Calculates the hash code for the current ValueTuple instance.

ToString()

Returns a string that represents the value of current ValueTuple instance.

Example:

C#
// Demonstration of Equals() Method in ValueTuple
using System;

class Geeks
{
	static public void Main()
	{
		// Creating 8-ValueTuple using Create method 
		var T1 = ValueTuple.Create(1, 2, 3, 4, 5, 6, 7 ,8);
		var T2 = ValueTuple.Create(1, 2, 3, 4, 5, 6, 7, 8);

		// Check if both the value 
		// tuples are equal or not 
		if (T1.Equals(T2)) {
			Console.WriteLine("Tuples Matched...!!");
		}
		else {
			Console.WriteLine("Tuples Not Matched...!!");
		}
	}
}

Output
Tuples Matched...!!


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