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();

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2022-12-23
  • 2021-06-21
  • 2021-09-02
  • 2021-08-05
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2021-10-25
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2023-01-15
相关资源
相似解决方案