Why does Assert.AreEqual(T obj1, Tobj2) fail with identical byte arrays

前端 未结 6 2010
日久生厌
日久生厌 2021-02-03 16:56

I have two identical byte arrays in the following segment of code:

    /// 
    ///A test for Bytes
    ///
    [TestMethod()]
            


        
6条回答
  •  被撕碎了的回忆
    2021-02-03 17:04

    Assert.Equals tests using the Equals method, which by default uses reference equality and, since they are different objects, they are not equal. You'll want to compare each byte in the array and verify that they are equal. One way to do this is convert them to something that implements ICollection and use CollectionAssert.AreEqual() instead.

提交回复
热议问题