Getting the String that Represent the Value of the Tuple<T1,T2,T3,T4,T5,T6,T7> 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> object. The string represented by this method is in the form of (Item1, Item2, Item3, Item4, Item5, Item6, Item7) here Item1, Item2, Item3, Item4, Item5, Item6, Item7 represent the values of Item1, Item2, Item3, Item4, Item5, Item6, Item7 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, T4, T5, T6, T7> object.
Example 1:
using System;
namespace exampleoftuple {
class GFG {
static void Main( string [] args)
{
var v1 = Tuple.Create( "Rohit" );
Console.WriteLine( "Tuple 1: " + v1.ToString());
var v2 = Tuple.Create( "Sheema" , "Riya" );
Console.WriteLine( "Tuple 2: " + v2.ToString());
var v3 = Tuple.Create( "Rima" , "Suman" , "Sohan" );
Console.WriteLine( "Tuple 3: " + v3.ToString());
var v4 = Tuple.Create( "Shilpa" , "Susma" ,
"Sumit" , "Rohan" );
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:
using System;
namespace exampleoftuple {
class GFG {
static public void Main()
{
var v5 = Tuple.Create(2, 4, 6, 8, 10);
Console.WriteLine( "Tuple 5: " + v5.ToString());
var v6 = Tuple.Create(3, 6, 9, 12, 15, 18);
Console.WriteLine( "Tuple 6: " + v6.ToString());
var v7 = Tuple.Create(12, 45, 67, 78, 87, 97, 87);
Console.WriteLine( "Tuple 7: " + v7.ToString());
}
}
}
|
Output:
Tuple 5: (2, 4, 6, 8, 10)
Tuple 6: (3, 6, 9, 12, 15, 18)
Tuple 7: (12, 45, 67, 78, 87, 97, 87)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...