C# ToTuple() Method

ProgrammingServer Side ProgrammingCsharp

Let’s say you have a ValueTuple and would like to convert it to a tuple, then use the ToTuple() method.

With C#, we can easily convert a ValueTuple to a Tuple using ToTuple() method.

Note − Add System.ValueTuple package to run ValueTuple program.

Let’s see how to add it −

  • Go to your project
  • Right click on the project in the solution explorer
  • Select “Manage NuGet Packages”
  • You will reach the NuGet Package Manager.
  • Now, click the Browse tab and find “ValueTuple”
  • Finally, add System.ValueTuple package

Let us see an example to implement ToTuple() method.


using System;
class Program {
   static void Main() {
      var val = (1, 2, 3);
      //Add System.ValueTuple package to run this program
      // ValueTuple
      Console.WriteLine(“ValueTuple: ” val);
      // Tuple
      Tuple<int, int, int> myTuple = val.ToTuple();
      Console.WriteLine(“Tuple: ”+myTuple);


ValueTuple: (1, 2, 3)
Tuple: (1, 2, 3)
Updated on 22-Jun-2020 15:31:26