首页 > 其他 > 详细

判断两个list是否含有重复值数据是否相同

时间:2020-09-02 17:07:16      阅读:317      评论:0      收藏:0      [点我收藏+]
  1. 比较代码 Except方法需要using System.Linq;
private bool CompareList(List<string>? beforeContractConsumerInbounds, List<string>? afterContractConsumerInbounds)
{
    if (beforeContractConsumerInbounds == null || beforeContractConsumerInboundCount == 0 
    || afterContractConsumerInbounds == null || afterContractConsumerInboundCount == 0)
        return false
    List<string> beforeConsumerInbounds = GetHashSortResult(beforeContractConsumerInbounds);
    List<string> afterConsumerInbounds = GetHashSortResult(afterContractConsumerInbounds)
    return beforeConsumerInbounds.Except(afterConsumerInbounds).Any() == false &&
           afterConsumerInbounds.Except(beforeConsumerInbounds).Any() == false;
}
  1. 得到过滤相同值后的结果
protected List<string> GetHashSortResult(List<string> listModel)
{
    HashSet<string> hashString = new HashSet<string>();
    foreach (string item in listModel)
    {
        hashString.Add(item);
    }
    List<string> listResult = new List<string>();
    listResult.AddRange(hashString.ToArray());
    return listResult;
}

判断两个list是否含有重复值数据是否相同

原文:https://www.cnblogs.com/andykk/p/13602383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!