Last Updated : 11 Jul, 2025
In C#, a 2-tuple is a
tuplethat contains two elements and it is also known as
pair. You can create a 2-tuple using two different ways:
Using Tuple<T1,T2>(T1, T2) ConstructorYou can create 2-tuple using Tuple<T1, T2>(T1, T2) constructor. It initializes a new instance of the Tuple<T1,T2> class. But when you create a tuple using this constructor then
you have to specify the type of the elementstored in the tuple.
Syntax:public Tuple (T1 item1, T2 item2);Parameters:
// C# program to create 2-tuple
// using the tuple constructor
using System;
public class GFG {
// Main method
static public void Main()
{
// Creating tuple with two elements
// Using Tuple<P1, P2>(T1, T2) constructor
Tuple<string, int> My_Tuple = new Tuple<string, int>("GeeksforGeeks", 10);
Console.WriteLine("Element 1: " + My_Tuple.Item1);
Console.WriteLine("Element 2: " + My_Tuple.Item2);
}
}
Output:
Element 1: GeeksforGeeks Element 2: 10Using Create Method
You can also create 2-tuple with the help of Create method. When you use this method then
there is no need to specify the type of the elementsstored in the tuple.
Syntax:public static Tuple<T1,T2> Create<T1, T2> (T1 item1, T2 item2);Type Parameters:
This method returns 2-tuple whose value is
item1and
item2.
Example: CSharp
// C# program to create 2-tuple
// using create method
using System;
public class GFG {
// Main method
static public void Main()
{
// Creating tuple with two elements
// Using Create method
var My_Tuple = Tuple.Create("Geeks", 20);
Console.WriteLine("Element 1: " + My_Tuple.Item1);
Console.WriteLine("Element 2: " + My_Tuple.Item2);
}
}
Output:
Element 1: Geeks Element 2: 20References:
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