본문 바로가기
C#/메서드 모음

[C#] Enumerable.Union() 메서드

by ju.__.nu 2024. 12. 13.

Enumerable.Union() 메서드

두 시퀀스를 중복이 생기지 않게 합쳐준다.


메서드 예제

int[] arr = { 1, 2, 3, 4, 5 };
int[] arr2 = { 1, 3, 5, 7, 9 };

arr = arr.Union(arr2).ToArray();
Console.WriteLine(string.Join(", ", arr)); // 1, 2, 3, 4, 5, 7, 9

 

1, 2, 3, 4, 5가 담긴 int array와 1, 3, 5, 7, 9가 담긴 int array를 합치면 중복이되는 1, 3, 5빼고 7, 9만 추가 되는 것을 확인할 수 있다.

 

 

 


다른 Enumerable 메서드 :) https://twd0622.tistory.com/14

 

[C#] Linq (Enumerable 클래스)

최근 수정: 2024.12.13Enumerable 클래스 내용 중 새로 알게되거나 사용했던 메서드들 기록하는 곳입니다. Enumerable 클래스Enumerable 클래스는 LINQ의 일부로 IEnumerable 인터페이스를 구현하는 컬렉션 클래

twd0622.tistory.com