From 2c7008d513e0de63a00e15e455114950b71c5fe8 Mon Sep 17 00:00:00 2001 From: soul liu Date: Fri, 12 May 2023 10:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0CollectionsUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- General/utils/CollectionsUtils.cs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) 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); + } } }