数组转换到HashSet&LT; T&GT;在.NET [英] Convert an array to a HashSet<T> in .NET
本文介绍了数组转换到HashSet&LT; T&GT;在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何转换成一个数组到一个哈希集合?
How do I convert an array to a hash set ?
string[] BlockedList = BlockList.Split(new char[] { ';' },
StringSplitOptions.RemoveEmptyEntries);
我要这个列表转换为的HashSet
。
推荐答案
您没有指定什么类型的 BlockedList
是的,所以我会假设它是什么,源于的IList
(如果想说字符串
,你写的黑名单
然后这将是一个字符串数组,其中来源于的IList
)。
You do not specify what type BlockedList
is, so I will assume it is something that derives from IList
(if meant to say String
where you wrote BlockList
then it would be a string array which derives from IList
).
的HashSet
有一个构造函数的的IEnumerable
,所以你需要仅仅列表传递到这个构造函数,如从
。的IList
派生的IEnumerable
HashSet
has a constructor that takes an IEnumerable
, so you need merely pass the list into this constructor, as IList
derives from IEnumerable
.
var set = new HashSet(BlockedList);
这篇关于数组转换到HashSet&LT; T&GT;在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文