Return a C# tuple from a method


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 23-Jun-2020

312 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements