Return a C# tuple from a method

ProgrammingServer Side ProgrammingCsharp

Firstly, create a tuple as shown below that calls a method.

var tuple = Show();

The above statement calls the following method −

static Tuple<int, int, int, int, int> Show()

Under the method, return the tuple as shown below −

Example

 Live Demo

using System;
public class Demo {
   public static void Main() {
      var tuple = Show();
      Console.WriteLine(tuple.Item1);
      Console.WriteLine(tuple.Item2);
      Console.WriteLine(tuple.Item3);
      Console.WriteLine(tuple.Item4);
      Console.WriteLine(tuple.Item5);
   }
   static Tuple<int, int, int, int, int> Show() {
      return Tuple.Create(3, 5, 7, 9, 11);
   }
}

Output

3
5
7
9
11
raja
Published on 11-Sep-2018 12:10:20
Advertisements