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;
}
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;
}
原文:https://www.cnblogs.com/andykk/p/13602383.html