Comparing two List for equality

后端 未结 9 1381
时光说笑
时光说笑 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:03

    Try the following

    var equal = expected.SequenceEqual(actual);
    

    Test Version

    Assert.IsTrue( actual.SequenceEqual(expected) );
    

    The SequenceEqual extension method will compare the elements of the collection in order for equality.

    See http://msdn.microsoft.com/en-us/library/bb348567(v=vs.100).aspx

提交回复
热议问题