Getting the String that Represent the Value of ValueTuple<T1,T2,T3,T4,T5,T6,T7,TRest> Instance in C#
Last Updated :
11 Dec, 2019
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
ToString Method.
This method returns a string that will represent the value of the ValueTuple<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 ValueTuple<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 ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> object.
Example 1:
CSharp
// C# program to illustrate
// the use of ToString method
using System;
namespace exampleofvaluetuple
{
class GFG
{
// Main Method
static void Main(string[] args)
{
// 1-ValueTuple
var v1 = ValueTuple.Create("Rina");
// Get the value of ValueTuple<T1>
// With the help of ToString method
Console.WriteLine("ValueTuple 1: " + v1.ToString());
// 2-ValueTuple
var v2 = ValueTuple.Create("Rohan", 25);
// Get the value of ValueTuple<T1, T2>
// With the help of ToString method
Console.WriteLine("ValueTuple 2: " + v2.ToString());
// 3-ValueTuple
var v3 = ValueTuple.Create("Rima", 22, 2016);
// Get the value of ValueTuple<T1, T2, T3>
// With the help of ToString method
Console.WriteLine("ValueTuple 3: " + v3.ToString());
// 4-ValueTuple
var v4 = ValueTuple.Create("Mohit", 28,
2014, "Junior Engineer");
// Get the value of ValueTuple<T1, T2, T3, T4>
// With the help of ToString method
Console.WriteLine("ValueTuple 4: " + v4.ToString());
}
}
}
Output:
ValueTuple 1: (Rina)
ValueTuple 2: (Rohan, 25)
ValueTuple 3: (Rima, 22, 2016)
ValueTuple 4: (Mohit, 28, 2014, Junior Engineer)
Example 2:
CSharp
// C# program to illustrate
// the use of ToString method
using System;
namespace exampleofvaluetuple
{
class GFG
{
// Main Method
static void Main(string[] args)
{
// 5-ValueTuple
var v5 = ValueTuple.Create("Rohit", 32,
2010, "CSE", "Junior Engineer");
// Get the value of ValueTuple<T1,
// T2, T3, T4, T5>
// With the help of ToString method
Console.WriteLine("ValueTuple 5: "+v5.ToString());
// 6-ValueTuple
var v6 = ValueTuple.Create("Sunita", 25, 2015,
"ECE", "Junior Engineer", 102);
// Get the value of ValueTuple<T1,
// T2, T3, T4, T5, T6>
// With the help of ToString method
Console.WriteLine("ValueTuple 6: "+v6.ToString());
// 7-ValueTuple
var v7 = ValueTuple.Create("Sonu", 22, 2016,
"CSE", "Junior Engineer", 104, "C++");
// Get the value of ValueTuple<T1,
// T2, T3, T4, T5, T6, T7>
// With the help of ToString method
Console.WriteLine("ValueTuple 7: "+v7.ToString());
// 8-ValueTuple
var v8 = ValueTuple.Create("Susmita",28, 2014,
"Junior Engineer", 109, "Java",
ValueTuple.Create("Cricket",
"Football", "Volleyball"));
// Get the value of ValueTuple<T1, T2, T3,
// T4, T5, T6, T7, TRest>
// With the help of ToString method
Console.WriteLine("ValueTuple 8: "+v8.ToString());
}
}
}
Output:
ValueTuple 5: (Rohit, 32, 2010, CSE, Junior Engineer)
ValueTuple 6: (Sunita, 25, 2015, ECE, Junior Engineer, 102)
ValueTuple 7: (Sonu, 22, 2016, CSE, Junior Engineer, 104, C++)
ValueTuple 8: (Susmita, 28, 2014, Junior Engineer, 109, Java, (Cricket, Football, Volleyball))
Similar Reads
Getting the String that Represent the Value of ValueTuple<T1,T2,T3,T4,T5,T6,T7> 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 ValueTuple<T1,T2,T3,T4,T5,T6> 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 ValueTuple<T1,T2,T3,T4,T5> 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,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,T7,TRest> 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, TRest> object. The string represente
3 min read