本文介绍了HashSet 转换为 List的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网上查到了这个,但我问这个是为了确保我没有错过任何东西.C# 中是否有将 HashSet 转换为 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 is, by definition, containing no duplicates. So there is no need for Distinct.
更多推荐
HashSet 转换为 List
发布评论