HashSet转换为List [英] HashSet conversion to List

查看:559
本文介绍了HashSet转换为List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在网上查找了此内容,但我要求这样做以确保我没有错过任何内容.是否有内置函数将HashSets转换为C#中的列表?我需要避免重复元素,但我需要返回一个List.

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 need to avoid duplicity of elements but I need to return a List.

推荐答案

这是我的处理方式:

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

根据定义,

HashSet不包含重复项.因此,不需要Distinct.

这篇关于HashSet转换为List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆