What's the difference between Assert.AreNotEqual and Assert.AreNotSame?

前端 未结 6 2121
情书的邮戳
情书的邮戳 2020-12-24 10:33

In C#, what\'s the difference between

Assert.AreNotEqual

and

Assert.AreNotSame
6条回答
  •  甜味超标
    2020-12-24 10:57

    Assert.AreNotEqual asserts that two values are not equal to each other.

    Assert.AreNotSame asserts that two variables do not point to the same object.

    Example 1:

    int i = 1;
    int j = i;
    // The values are equal:
    Assert.AreEqual(i, j);
    // Two value types do *not* represent the same object:
    Assert.AreNotSame(i, j);
    

    Example 2:

    string s = "A";
    string t = s;
    // The values are equal:
    Assert.AreEqual(s, t);
    // Reference types *can* point to the same object:
    Assert.AreSame(s, t);
    

提交回复
热议问题