diff --git a/General/utils/CollectionsUtils.cs b/General/utils/CollectionsUtils.cs index c43d062..cf5993c 100644 --- a/General/utils/CollectionsUtils.cs +++ b/General/utils/CollectionsUtils.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.VisualBasic; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -6,13 +7,13 @@ using System.Text; using System.Threading.Tasks; namespace Soul2.General.utils { - public class CollectionsUtils { + public static class CollectionsUtils { /// /// 判断非空 /// /// 集合对象 /// 是否非空 - public static bool isNotEmpty(IEnumerable collection) { + public static bool isNotEmpty(this IEnumerable collection) { return !isEmpty(collection); } @@ -21,7 +22,7 @@ namespace Soul2.General.utils { /// /// 集合对象 /// 是否为空 - public static bool isEmpty(IEnumerable collection) { + public static bool isEmpty(this IEnumerable collection) { if (collection == null) { return true; } @@ -30,5 +31,24 @@ namespace Soul2.General.utils { } return true; } + + /// + /// 去重 + /// + /// + /// + /// + public static List duplicateRemoval(this List list) { + if (list.isNotEmpty()) { + var set = new HashSet(list); + return new List(set); + } else { + return list; + } + } + + public static HashSet toSet(this IEnumerable collection) { + return new HashSet(collection); + } } }