判斷兩個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