C# program to create a ValueType with names

ProgrammingServer Side ProgrammingCsharp

With C# 7, you can easily create a ValueType with names.

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 myTuple = (marks: 95, name: "jack", subject: "maths");
      //Add System.ValueTuple package to run this program
      // using names to access
      Console.WriteLine("Student Marks: "+myTuple.marks);
      Console.WriteLine("Student Name: "+myTuple.name);
      Console.WriteLine("Student Subject: "+myTuple.subject);
   }
}

Output

Student Marks: 95
Student Name: Jack
Student Subject: Maths
raja
Published on 11-Sep-2018 08:54:48
Advertisements