Home > Backend Development > C#.Net Tutorial > Convert ValueTuple to Tuple in C#

Convert ValueTuple to Tuple in C#

WBOY
Release: 2023-09-11 12:13:02
forward
623 people have browsed it

在 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);
   }
}
Copy after login

Output

ValueTuple: (5, 50, 500, 5000)
Tuple: (5, 50, 500, 5000)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template