zoukankan      html  css  js  c++  java
  • 关于distinct的compare参数的使用

    1.创建compare类

    using DCZY.Bean;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace DCZY.Bean
    {
        public class HookPlanMonitorDeviceCompare : IEqualityComparer<HookPlanMonitorDeviceInfo>
        {
            public bool Equals(HookPlanMonitorDeviceInfo x, HookPlanMonitorDeviceInfo y)
            {
                if (x.Device.Name == y.Device.Name)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
    
            public int GetHashCode(HookPlanMonitorDeviceInfo obj)
            {
                int hCode = obj.Device.Name.GetHashCode();
                return hCode.GetHashCode();
            }
        }
    }

    2.调用

    List<HookPlanMonitorDevice> devicecollection = devicecollection.Distinct(new HookPlanMonitorDeviceCompare()).ToList();
    萌橙 你瞅啥?
  • 相关阅读:
    20210603
    20210602
    20210601
    20210531-已编辑
    2021053101
    操作系统笔记(一)
    尘埃落定,扬帆起航
    RTL级低功耗设计
    关于毛刺
    电路级拾珍
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/11377108.html
Copyright © 2011-2022 走看看