Comparing two List for equality

后端 未结 9 1396
时光说笑
时光说笑 2020-12-01 11:30

Other than stepping through the elements one by one, how do I compare two lists of strings for equality (in .NET 3.0):

This fails:

// Expected re         


        
9条回答
  •  甜味超标
    2020-12-01 12:15

    If the order matters:

    bool equal = a.SequenceEquals(b);
    

    If the order doesn't matter:

    bool equal = a.Count == b.Count && new HashSet(a).SetEquals(b);
    

提交回复
热议问题