C# Value Tuple


A value type representation of the C# Tuple is Value Type Tuple. It was introduced in C# 7.0.

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

Example

using System;
class Program {
   static void Main() {
      var val = (5, 50, 500, 5000);
      Console.WriteLine("Add System.ValueTuple package to run this program!");
      if (val.Item2 == 50) {
         Console.WriteLine(val);
      }
   }
}

Output

The following is the output.

(5, 50, 500, 5000);

Updated on: 10-Apr-2020

42 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements