Getting the String that Represent the Value of the Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> Instance in C#
Last Updated :
11 Dec, 2019
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, TRest> object. The string represented by this method is in the form of (Item1, Item2, Item3, Item4, Item5, Item6, Item7, Item8..) here Item1, Item2, Item3, Item4, Item5, Item6, Item7 represent the values of Item1, Item2, Item3, Item4, Item5, Item6, Item7 properties, and Item8 represents the value of the Tuple<T1, T2, T3, T4, T5, T6, T7, TRest> object's Next.Item1 property and the value of any additional nested components are followed by Item8. 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, T4, T5, T6, T7, TRest> 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());
// 4-Tuple
var v4 = Tuple.Create("Shilpa", "Susma",
"Sumit", "Rohan");
// Get the value of Tuple<T1, T2, T3, T4>
// With the help of ToString method
Console.WriteLine("Tuple 4: " + v4.ToString());
}
}
}
Output:
Tuple 1: (Rohit)
Tuple 2: (Sheema, Riya)
Tuple 3: (Rima, Suman, Sohan)
Tuple 4: (Shilpa, Susma, Sumit, Rohan)
Example 2:
CSharp
// C# program to illustrate the
// use of ToString method
using System;
namespace exampleoftuple {
class GFG {
// Main Method
static void Main(string[] args)
{
// 5-Tuple
var v5 = Tuple.Create("G", "E", "E", "K", "S");
// Get the value of Tuple<T1, T2, T3, T4, T5>
// With the help of ToString method
Console.WriteLine("Tuple 5: " + v5.ToString());
// 6-Tuple
var v6 = Tuple.Create("C", "C#", "C++",
"Python", "Java", "Perl");
// Get the value of Tuple<T1, T2, T3, T4, T5, T6>
// With the help of ToString method
Console.WriteLine("Tuple 6: " + v6.ToString());
// 7-Tuple
var v7 = Tuple.Create(12, 45, 67, 78, 87, 97, 87);
// Get the value of Tuple<T1, T2,
// T3, T4, T5, T6, T7>
// With the help of ToString method
Console.WriteLine("Tuple 7: " + v7.ToString());
// 8-Tuple
var v8 = Tuple.Create("G", "E", "E", "K", "S",
"F", "O", Tuple.Create("R", "G", "E",
"E", "K", "S"));
// Get the value of Tuple<<T1, T2, T3,
// T4, T5, T6, T7, TRest>
// With the help of ToString method
Console.WriteLine("Tuple 8: " + v8.ToString());
}
}
}
Output:
Tuple 5: (G, E, E, K, S)
Tuple 6: (C, C#, C++, Python, Java, Perl)
Tuple 7: (12, 45, 67, 78, 87, 97, 87)
Tuple 8: (G, E, E, K, S, F, O, (R, G, E, E, K, S))
Similar Reads
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
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> 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 ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> Instance in C# ValueTuple is a structure introduced in C# 7.0 which represents the value type Tuple. It allows you to store a data set that contains multiple values that may or may not be related to each other. You can also get a string that represents the value of the ValueTuple's object with the help of the ToSt
3 min read
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