[C#] 纯文本查看 复制代码 List<Order> listA = new List<Order>();
listA.Add(new Order { ProCode = "111" });
listA.Add(new Order { ProCode = "222" });
listA.Add(new Order { ProCode = "333" });
List<Order> listB = new List<Order>();
listB.Add(new Order { ProCode = "111" });
listB.Add(new Order { ProCode = "222" });
listB.Add(new Order { ProCode = "333" });
if (IsEqual(listA, listB))
{
Console.WriteLine("相等");
}
else
{
Console.WriteLine("不相等");
} 最后输出不相等
[C#] 纯文本查看 复制代码 List<int> lista = new List<int> { 1, 2, 3, 4, 5, 6 };
List<int> listb = new List<int> { 1, 2, 3, 5, 4, 6 };
if (IsEqual(lista, listb))
{
Console.WriteLine("相等");
}
else
{
Console.WriteLine("不相等");
}
这段最后输出结果是相等
[C#] 纯文本查看 复制代码 public bool IsEqual<T>(IList<T> ListA, IList<T> ListB)
{
if (ListA.Count != ListB.Count)
return false;
foreach (T item in ListA)
{
if (!ListB.Contains(item))
return false;
}
return true;
}
[C#] 纯文本查看 复制代码 public class Order
{
public string ProCode { get; set; }
public string Code { get; set; }
} |