Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# ToTuple() Method
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.
Example
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);
}
}
Output
ValueTuple: (1, 2, 3) Tuple: (1, 2, 3)
Advertisements