从方法返回C#元组
首先,如下所示创建一个元组,调用一个方法。
var tuple = Show();
上面的语句调用以下方法-
static Tuple<int, int, int, int, int> Show()
在该方法下,返回元组,如下所示:
示例
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); } }
输出结果
3 5 7 9 11