如何在 C# 中将元组转换为数组?


首先,设置元组 -

Tuple<int, int> t = Tuple.Create(99,53);

现在,将元组转换为数组 -

int[] arr = new int[]{t.Item1, t.Item2};

以下是将元组转换为数组的代码 -

示例

 实时演示

using System;
using System.Linq;
using System.Collections.Generic;

namespace Demo {
   public class Program {
      public static void Main(string[] args) {
         Tuple<int, int> t = Tuple.Create(99,53);
         int[] arr = new int[]{t.Item1, t.Item2};

         foreach (int val in arr) {
            Console.WriteLine(val);
         }
      }
   }  
}

输出

99
53

更新于: 22-Jun-2020

833 次查看

开启你的 事业

完成课程,获得认证

开始
广告
© . All rights reserved.