用方法返回 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

更新日期:2020 年 6 月 23 日

341 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

立即開始
廣告
© . All rights reserved.