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


  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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM