相关文章推荐
傻傻的作业本  ·  mongodb atlas filters ...·  2 年前    · 
焦虑的柑橘  ·  VSCode集成终端上不能使用Ctrl+C命 ...·  2 年前    · 
踏实的汉堡包  ·  Python爬虫实战.pdf_技术_速成_项目·  3 年前    · 
爱跑步的草稿纸  ·  PHP-Guzzle异步、并发_江天暮雪丨的 ...·  3 年前    · 
没人理的玉米  ·  double machine ...·  3 年前    · 
Code  ›  C# Tuple<T1,T2,T3,T4,T5> Class - GeeksforGeeks
t3
https://www.geeksforgeeks.org/c-sharp/c-sharp-tuple-5-class/
满身肌肉的毛衣
2 月前
geeksforgeeks
  • Courses
  • Tutorials
  • Interview Prep
  • C# Tutotrial
  • Projects
  • Data Types
  • Methods
  • Constructors
  • Arrays
  • Tuple
  • Indexers
  • Interface
  • Multithreading
  • Exception
  • C

C# Tuple<T1,T2,T3,T4,T5> Class

Last Updated : 11 Jul, 2025

Tuple<T1, T2, T3, T4, T5> class creates a 5 Tuple or quintuple. It represents a tuple that contains five elements. We can instantiate a Tuple<T1, T2, T3, T4, T5> object by calling either the Tuple<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5) constructor or by the static Tuple.Create method.

  • It implements the IStructuralComparable, IStructuralEquatable, and IComparable interface.
  • It is defined under the System namespace.
  • It represents multiple data into a single data set.
  • It allows us to create, manipulate, and access data sets.
  • It returns multiple values from a method without using out parameter .
  • It allows multiple values to be passed to a method with the help of single parameters.
  • It can also store duplicate elements.

Constructor

Tuple<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5)

Property

We can retrieve the value of Tuple<T1, T2, T3, T4, T5> object’s elements using the read-only Item<ElementNumber> instance properties.

  • Item1 : Gets the value of the first component of the tuple.
  • Item2 : Gets the value of the second component of the tuple.
  • Item3 : Gets the value of the third component of the tuple.
  • Item4 : Gets the value of the fourth component of the tuple.
  • Item5 : Gets the value of the fifth component of the tuple.

Example:

using System;
class Geeks
	static public void Main()
		// Creating 5-Tuple using Tuple constructor
		Tuple<int, int, int, string, int> t =
          new Tuple<int,int, int, string, int>
          	(79, 34, 67, "Geeks", 44);
		// Accessing the values
		Console.WriteLine("Value of the First Component: " + t.Item1);
		Console.WriteLine("Value of the Second Component: " + t.Item2);
		Console.WriteLine("Value of the Third Component: " + t.Item3);
		Console.WriteLine("Value of the Fourth Component: " + t.Item4);
		Console.WriteLine("Value of the Fifth Component: " + t.Item5);

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

Methods

There are some important methods which are used in tuples are given below:

Method

Description

Equals(Object)

Returns a value that indicates whether the current Tuple<T1, T2, T3, T4, T5> object is equal to a specified object.

GetHashCode()

Returns the hash code for the current Tuple<T1, T2, T3, T4, T5> 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> instance.

Example: Demonstration of Equals() Method.

// Using constructor and property
// of Tuple Class
using System;
class Geeks
	static public void Main()
		// Creating 5-Tuple using constructor
		Tuple<int, int, int, int, int> t1 = 
          new Tuple<int, int, int, int, int>
          	(20, 40, 90, 89, 33);
		Tuple<int, int, int, int, int> t2 = 
          new Tuple<int, int, int, int, int>
          	(20, 40, 90, 89, 33);
		// Using Equals method
		if (t1.Equals(t2))
			Console.WriteLine("Tuple Matched..");
 
推荐文章
傻傻的作业本  ·  mongodb atlas filters in ADF source is not working. returning no records! - Microsoft Q&A
2 年前
焦虑的柑橘  ·  VSCode集成终端上不能使用Ctrl+C命令复制文本。 -火山引擎
2 年前
踏实的汉堡包  ·  Python爬虫实战.pdf_技术_速成_项目
3 年前
爱跑步的草稿纸  ·  PHP-Guzzle异步、并发_江天暮雪丨的博客-CSDN博客
3 年前
没人理的玉米  ·  double machine learning for causal inference-掘金
3 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号