在 C# 中設定 6 項元組


使用 C#,您可以輕鬆地設定一個包含 6 個項的元組。

以下是一個包含 6 個項的元組 -

var myTuple = new Tuple<string, string[], int, int, int, int>("electronics",
new string[] { "shoes", "clothing#", "accessories" },
100,
250,
500,
1000);

上面,我們為字串、字串陣列和 int 建立了元組,如下所示 -

Tuple<string, string[], int, int, int, int>

以下是完整程式碼 -

示例

 即時演示

using System;
class Demo {
   static void Main() {
      var myTuple = new Tuple<string, string[], int, int, int, int>("electronics",
      new string[] { "shoes", "clothing#", "accessories" },
      100,
      250,
      500,
      1000);
      // Displaying Item 1
      Console.WriteLine(myTuple.Item1);
      // Displaying Item 5
      Console.WriteLine(myTuple.Item5);
      // Displaying Item 6
      Console.WriteLine(myTuple.Item6);
   }
}

輸出

electronics
500
1000

更新於: 2020 年 6 月 22 日

73 次瀏覽

開啟你的 職業

完成課程獲得認證

開始
廣告