In C#, a 5-tuple is a tuple that contains five elements and it is also known as quintuple. You can create a 5-tuple using two different ways:
Using Tuple<T1,T2,T3,T4,T5>(T1, T2, T3, T4, T5) Constructor
You can create 5-tuple using Tuple<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5) constructor. It initializes a new instance of the Tuple<T1, T2, T3, T4, T5> class. But when you create a tuple using this constructor then you have to specify the type of the element stored in the tuple.
Syntax:
public Tuple (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5);
Parameters:
- item1: It is the value of the first tuple component.
- item2: It is the value of the second tuple component.
- item3: It is the value of the third tuple component.
- item4: It is the value of the fourth tuple component.
- item5: It is the value of the fifth tuple component.
Example:
// C# program to create 5-tuple // using the tuple constructor using System; public class GFG { // Main method static public void Main() { // Creating tuple with five elements // Using Tuple<T1, T2, T3, T4, T5>(T1, // T2, T3, T4, T5) constructor Tuple<string, int, char, double, string> My_Tuple = new Tuple<string, int, char, double, string>("GeeksforGeeks", 10, 'G', 20.4, "Geeks"); Console.WriteLine("Element 1: " + My_Tuple.Item1); Console.WriteLine("Element 2: " + My_Tuple.Item2); Console.WriteLine("Element 3: " + My_Tuple.Item3); Console.WriteLine("Element 4: " + My_Tuple.Item4); Console.WriteLine("Element 5: " + My_Tuple.Item5); } } |
Element 1: GeeksforGeeks Element 2: 10 Element 3: G Element 4: 20.4 Element 5: Geeks
Using Create Method
You can also create 5-tuple with the help of Create method. When you use this method then there is no need to specify the type of the elements stored in the tuple.
Syntax:
public static Tuple<T1,T2,T3,T4,T5> Create<T1, T2, T3, T4, T5> (T1 item1, T2 item2, T3 item3, T4 item4, T5 item5);
Type Parameters:
- T1: It is the type of the first tuple component.
- T2: It is the type of the second tuple component.
- T3: It is the type of the third tuple component.
- T4: It is the type of the fourth tuple component.
- T5: It is the type of the fifth tuple component.
Parameters:
- item1: It is the value of the first tuple component.
- item2: It is the value of the second tuple component.
- item3: It is the value of the third tuple component.
- item4: It is the value of the fourth tuple component.
- item5: It is the value of the fifth tuple component.
Return Type: This method returns 5-tuple whose value is item1, item2, item3, item4 and item5.
Example:
// C# program to create 5-tuple // using create method using System; public class GFG { // Main method static public void Main() { // Creating tuple with five elements // Using Create method var My_Tuple = Tuple.Create("Geeks", 20, 'f', 340.6, "GeeksforGeeks"); Console.WriteLine("Element 1: " + My_Tuple.Item1); Console.WriteLine("Element 2: " + My_Tuple.Item2); Console.WriteLine("Element 3: " + My_Tuple.Item3); Console.WriteLine("Element 4: " + My_Tuple.Item4); Console.WriteLine("Element 5: " + My_Tuple.Item5); } } |
Element 1: Geeks Element 2: 20 Element 3: f Element 4: 340.6 Element 5: GeeksforGeeks
Reference:
- https://docs.microsoft.com/en-us/dotnet/api/system.tuple-5.-ctor?view=netframework-4.8
- https://docs.microsoft.com/en-us/dotnet/api/system.tuple.create?view=netframework-4.8#System_Tuple_Create__5___0___1___2___3___4_
Recommended Posts:
- Different ways to create an Object in C#
- C# | Create a Stack from a collection
- C# | Create a Queue from another collection
- C# | How to create a SortedSet
- C# | How to create a SortedList
- How to create 3-Tuple or Triple Tuple in C#?
- C# | Create HashSet from another collection
- How to create a shallow copy of SortedList Object in C#
- How to create Threads in C#
- How to create a shallow copy of Hashtable in C#
- How to create a shallow copy of ArrayList in C#
- How to create a shallow copy of BitArray in C#
- How to create a Queue in C#
- How to create the ArrayList in C#
- C# | How to create a Stack
- C# | How to create a shallow copy of the BitArray
- How to create a StringDictionary in C#
- How to create an OrderedDictionary in C#
- How to create a StringCollection in C#
- How to create a ListDictionary in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

