HashSet을 초기화하려면.
var h = new HashSet<string>(arr1);
위에서 HashSet에 배열을 설정했습니다. 다음은 배열입니다 -
string[] arr1 = {
"electronics",
"accessories”,
"electronics",
}; 다음은 C#에서 HashSet을 구현하는 방법을 보여주는 예입니다 -
예
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
string[] arr1 = {
"electronics",
"accessories”,
"electronics",
};
Console.WriteLine(string.Join(",", arr1));
// HashSet
var h = new HashSet(arr1);
// eliminates duplicate words
string[] arr2 = h.ToArray();
Console.WriteLine(string.Join(",", arr2));
}
}