HashSet conversion to List

后端 未结 4 1771
时光说笑
时光说笑 2021-01-07 16:17

I have looked this up on the net but I am asking this to make sure I haven\'t missed out on something. Is there a built-in function to convert HashSets to Lists in C#? I nee

4条回答
  •  不思量自难忘°
    2021-01-07 16:58

    Here's how I would do it:

       using System.Linq;
       HashSet hset = new HashSet();
       hset.Add(10);
       List hList= hset.ToList();
    

    HashSet is, by definition, containing no duplicates. So there is no need for Distinct.

提交回复
热议问题