Tuple Rest Property in C#

CsharpProgrammingServer Side Programming

Create tuples of eight or more elements by nesting tuple objects in the Rest property.

The tuple would look like −

Tuple<T1, T2, T3, T4, T5, T6, T7, TRest>

Above, the 8th element is added using Rest property.

Let us see an example.

Example

 Live Demo

using System;
public class Program {
   public static void Main() {
      var myTuple = Tuple.Create(1, 2.5M, "Tom", "100", 5, 10.5M, "Henry", "100");
      Console.WriteLine("Item1 : "+ myTuple.Item1);
      Console.WriteLine("Item2 : "+ myTuple.Item2);
      Console.WriteLine("Item3 : "+ myTuple.Item3);
      Console.WriteLine("Item4 : "+ myTuple.Item4);
      Console.WriteLine("Item5 : "+ myTuple.Item5);
      Console.WriteLine("Item6 : "+ myTuple.Item6);
      Console.WriteLine("Item7 : "+ myTuple.Item7);
      Console.WriteLine("Item8 : "+ myTuple.Rest);
   }
}

Output

Item1 : 1
Item2 : 2.5
Item3 : Tom
Item4 : 100
Item5 : 5
Item6 : 10.5
Item7 : Henry
Item8 : (100)
raja
Published on 14-Sep-2018 14:57:31
Advertisements