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 | /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sources"></param> /// <param name="details"></param> /// <param name="mdRelation"></param> /// <returns></returns> public static List<T> Intersect<T>( this List<T> sources, List<T> details, Func<T, T, bool > compareCond) { List<T> result = new List<T>(); sources?.ForEach(item => { details?.ForEach(detail => { if (compareCond(detail, item)) { result.Add(item); return ; } }); }); return result; } /// <summary> /// 取差集合 A-B,A集合中有B集合中无的 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sources"></param> /// <param name="details"></param> /// <param name="compareCond"></param> /// <returns></returns> public static List<T> Expect<T>( this List<T> sources, List<T> details, Func<T, T, bool > compareCond) { List<T> result = new List<T>(); sources?.ForEach(item => { if (!details.Exist<T>(item, compareCond)) { result.Add((T)item); } }); return result; } /// <summary> /// 取并集(A和B取并集,共通的项目选A) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="source"></param> /// <param name="entity"></param> /// <param name="compareCond"></param> /// <returns></returns> public static List<T> Union<T>( this List<T> source, List<T> target, Func<T, T, bool > compareCond) { List<T> result = new List<T>(); result.AddRange(source); target?.ForEach(item => { if (!target.Exist<T>(item, compareCond)) { result.Add(item); } }); return result; } /// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public static bool Exist<T>( this List<T> source, T entity,Func<T, T, bool > compareCond) { bool bExist = false ; source.ForEach(item => { if (compareCond(item, entity)) { bExist = true ; return ; } }); return bExist; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
2019-12-26 C# 扩展