当前位置:首页 > Windows程序 > 正文

c#比较两个List相等

2021-03-29 Windows程序

1、if(ListA.Count == ListB.Count && ListA.Count(t => !ListB.Contains(c)) == 0)

数量相等,元素值相等即为True;与元素顺序无关;

List<int> A = new List<int> {1,2,3};

List<int> B = new List<int> {1,3,2};

A == B;

2、if (ListA.SequenceEqual(ListB))

数量相等,值相等,,顺序一样时为True;

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69580.html