Assert IEnumerables

前端 未结 4 1494
死守一世寂寞
死守一世寂寞 2021-02-18 19:10

As unit testing is not used in our firm, I\'m teaching myself to unit test my own code. I\'m using the standard .net test framework for some really basic unit testing.

A

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-18 19:59

    You want the SequenceEqual() extension method (LINQ):

        string[] x = { "abc", "def", "ghi" };
        List y = new List() { "abc", "def", "ghi" };
    
        bool isTrue = x.SequenceEqual(y);
    

    or just:

       bool isTrue = x.SequenceEqual(new[] {"abc","def","ghi"});
    

    (it will return false if they are different lengths, or any item is different)

提交回复
热议问题