Computer >> 컴퓨터 >  >> 프로그램 작성 >> C#

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