Getting the String that Represent the Value of the Tuple<T1,T2,T3> Instance in C#
Last Updated :
12 Jul, 2025
A
tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the
ToString Method. This method returns a string that will represent the Tuple<T1, T2, T3> object. The string represented by this method is in the form of (Item1, Item2, Item3) here Item1, Item2, Item3 represent the values of Item1, Item2, Item3 properties. And it will represent a
String.Empty if any property contains a null value.
Syntax:
public override string ToString ();
Return Type: The return type of this method is
System.String. So, it will return a string that represents Tuple<T1, T2, T3> object.
Example 1:
CSharp
// C# program to illustrate
// the use of ToString method
using System;
namespace exampleoftuple {
class GFG {
// Main Method
static void Main(string[] args)
{
// 1-Tuple
var v1 = Tuple.Create("Rohit");
// Get the value of Tuple<T1>
// With the help of ToString method
Console.WriteLine("Tuple 1: " + v1.ToString());
// 2-Tuple
var v2 = Tuple.Create("Sheema", "Riya");
// Get the value of Tuple<T1, T2>
// With the help of ToString method
Console.WriteLine("Tuple 2: " + v2.ToString());
// 3-Tuple
var v3 = Tuple.Create("Rima", "Suman", "Sohan");
// Get the value of Tuple<T1, T2, T3>
// With the help of ToString method
Console.WriteLine("Tuple 3: " + v3.ToString());
}
}
}
Output:
Tuple 1: (Rohit)
Tuple 2: (Sheema, Riya)
Tuple 3: (Rima, Suman, Sohan)
Example 2:
CSharp
// C# program to illustrate
// the use of ToString method
using System;
namespace exampleoftuple {
class GFG {
// Main Method
static public void Main()
{
// Nested Tuples
var T1 = Tuple.Create("Sumit", Tuple.Create("Bongo",
"Bella", "Binu"));
var T2 = Tuple.Create("Boond", "Cinki", "Chimmy",
Tuple.Create("Karan", "Micky"));
var T3 = Tuple.Create(34.9, 78.7,
Tuple.Create(12.2, 34.5, 5.6, .78));
var T4 = Tuple.Create(2, 4, 6, 8, 5,
Tuple.Create(10, 20, 30, 40, 50));
// Get the value of Nested Tuples
// With the help of ToString method
Console.WriteLine("NTuple 1: {0}", T1.ToString());
Console.WriteLine("NTuple 2: {0}", T2.ToString());
Console.WriteLine("NTuple 3: {0}", T3.ToString());
Console.WriteLine("NTuple 4: {0}", T4.ToString());
}
}
}
Output:
NTuple 1: (Sumit, (Bongo, Bella, Binu))
NTuple 2: (Boond, Cinki, Chimmy, (Karan, Micky))
NTuple 3: (34.9, 78.7, (12.2, 34.5, 5.6, 0.78))
NTuple 4: (2, 4, 6, 8, 5, (10, 20, 30, 40, 50))
Similar Reads
Getting the String that Represent the Value of the Tuple<T1,T2,T3,T4> Instance in C# A tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the ToString Method. This method returns a string that will represent the Tuple<T1, T2, T3, T4> object. The string represented by this method is
3 min read
Getting the String that Represent the Value of the Tuple<T1,T2> Instance in C# A tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the ToString Method. This method returns a string that will represent the Tuple<T1, T2> object. The string represented by this method is in the
2 min read
Getting the String that Represent the Value of the Tuple<T1,T2,T3,T4,T5> Instance in C# A tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the ToString Method. This method returns a string that will represent the Tuple<T1, T2, T3, T4, T5> object. The string represented by this metho
3 min read
Getting the String that Represent the Value of the Tuple<T1> Instance in C# A tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the ToString Method. This method returns a string that will represent the Tuple<T1> object. The string represented by this method is in the form
2 min read
Getting the String that Represent the Value of the Tuple<T1,T2,T3,T4,T5,T6> Instance in C# A tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the ToString method. This method returns a string that will represent the Tuple<T1, T2, T3, T4, T5, T6> object. The string represented by this m
3 min read
Getting the String that Represent the Value of the Tuple<T1,T2,T3,T4,T5,T6,T7> Instance in C# A tuple is a data structure that gives you the easiest way to represent a data set. You can also get a string that represents a tuple object by using the ToString Method. This method returns a string that will represent the Tuple<T1, T2, T3, T4, T5, T6, T7> object. The string represented by th
3 min read