在 C# 中设置 6 项元组

csharpprogrammingserver side programming更新于 2025/9/22 18:07:17

使用 C#,您可以轻松设置 6 项元组。

以下是一个 6 项元组 −

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

上面,我们有分别用于字符串、字符串数组和整数的元组,如下所示 −

元组<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);
      // 显示项目 1
      Console.WriteLine(myTuple.Item1);
      // 显示项目 5
      Console.WriteLine(myTuple.Item5);
      // 显示项目 6
      Console.WriteLine(myTuple.Item6);
   }
}

输出

electronics
500
1000

相关文章