Home  >  Article  >  Backend Development  >  Convert ValueTuple to Tuple in C#

Convert ValueTuple to Tuple in C#

WBOY
WBOYforward
2023-09-11 12:13:02568browse

在 C# 中将 ValueTuple 转换为元组

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

Note - Add the System.ValueTuple package to run the ValueTuple program.

>

Let's see how to add it -

  • Go to your project
  • Right click on the project in Solution Explorer
  • Select "Manage NuGet Packages"
  • You will arrive at the NuGet Package Manager.
  • Now, click on the "Browse" tab and find "ValueTuple"
  • Finally, add the System.ValueTuple package

Example

using System;
class Program {
   static void Main() {
      var val = (5, 50, 500, 5000);
      //Add System.ValueTuple package to run this program
      // ValueTuple
      Console.WriteLine(“ValueTuple: ” val);

      // Tuple
      Tuple<int, int, int, int> myTuple = val.ToTuple();
      Console.WriteLine(&ldquo;Tuple: &rdquo;+myTuple);
   }
}

Output

ValueTuple: (5, 50, 500, 5000)
Tuple: (5, 50, 500, 5000)

The above is the detailed content of Convert ValueTuple to Tuple in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete