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
Updated on: 2020-06-23T06:52:32+05:30

386 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements