wyb
2021-05-11 49ce087bd2a34a150597e1cc1da157af242c0b6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Pcb.Common
{
    /// <summary>
    /// 列表扩展
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public static class extEnumerable
    {
        #region 转换成散列集合
        /// <summary>
        /// 转换成HashSet
        /// </summary>
        /// <typeparam name="T">列表项类型</typeparam>
        /// <param name="List">枚举列表</param>
        /// <returns>HashSet</returns>
        public static HashSet<T> _ToHashSet<T>(this IEnumerable<T> List)
        {
            var hs = new HashSet<T>();
            foreach (var i in List) { hs.Add(i); }
            return hs;
        }
        /// <summary>
        /// 转换成HashSet
        /// </summary>
        /// <typeparam name="T">列表项类型</typeparam>
        /// <param name="List">枚举列表</param>
        /// <returns>HashSet</returns>
        public static HashSet<T> _ToHashSet<T>(this IEnumerable List)
        {
            var hs = new HashSet<T>();
            foreach (T i in List) { hs.Add(i); }
            return hs;
        }
        /// <summary>
        /// 转换成HashSet
        /// </summary>
        /// <typeparam name="T">列表项类型</typeparam>
        /// <typeparam name="TValue">其它类型</typeparam>
        /// <param name="List">枚举列表</param>
        /// <param name="Select">选择键函数</param>
        /// <returns>数组</returns>
        public static HashSet<TValue> _ToHashSet<T, TValue>(this IEnumerable<T> List, Func<T, TValue> Select)
        {
            var hs = new HashSet<TValue>();
            foreach (var i in List) { hs.Add(Select(i)); }
            return hs;
        }
        /// <summary>
        /// 转换成HashSet
        /// </summary>
        /// <typeparam name="T">列表项类型</typeparam>
        /// <typeparam name="TValue">其它类型</typeparam>
        /// <param name="List">枚举列表</param>
        /// <param name="Select">选择键函数</param>
        /// <returns>数组</returns>
        public static HashSet<TValue> _ToHashSet<T, TValue>(this IEnumerable List, Func<T, TValue> Select)
        {
            var hs = new HashSet<TValue>();
            foreach (T i in List) { hs.Add(Select(i)); }
            return hs;
        }
        /// <summary>
        /// 转换成其它类型列表
        /// </summary>
        /// <typeparam name="TValue">其它类型</typeparam>
        /// <param name="List">数据行列表</param>
        /// <param name="Select">选择键函数</param>
        /// <returns>列表</returns>
        public static HashSet<TValue> _ToHashSet<TValue>(this System.Data.DataRowCollection List, Func<System.Data.DataRow, TValue> Select)
        {
            HashSet<TValue> lst = new HashSet<TValue>();
            foreach (System.Data.DataRow i in List) { lst.Add(Select(i)); }
            return lst;
        }
        /// <summary>
        /// 转换成其它类型列表
        /// </summary>
        /// <typeparam name="TValue">其它类型</typeparam>
        /// <param name="List">数据行列表</param>
        /// <param name="Select">选择键函数</param>
        /// <returns>列表</returns>
        public static HashSet<TValue> _ToHashSet<TValue>(this System.Data.DataColumnCollection List, Func<System.Data.DataColumn, TValue> Select)
        {
            HashSet<TValue> lst = new HashSet<TValue>();
            foreach (System.Data.DataColumn i in List) { lst.Add(Select(i)); }
            return lst;
        }
        #endregion
    }
}