如何在 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 次檢視

開啟你的 事業

完成課程,獲得認證

開始
廣告