Difference between Assert.AreEqual and Assert.AreSame?

What is the difference between Assert.AreEqual and Assert.AreSame ?

+45
c # assert
Jun 11 '14 at 21:20
source share
2 answers

This means that AreSame () checks that they are the same object - if the link points to the same object in memory.

AreEqual () verifies that objects are of the same type and value. Equal objects can exist in two different places in memory.

+56
Jun 11 '14 at 21:27
source share

Assert.AreEqual(a, b) same as Assert.IsTrue(Object.Equals(a, b))

Assert.AreSame(a, b) same as Assert.IsTrue(Object.ReferenceEquals(a, b))

(the only reason I knew, I just thought about it a few hours ago because I needed to do Assert.IsTrue(Object.ReferenceEquals(a,b)) and thought: "I wonder if there is a better way to do this" )

+41
Jun 11 '14 at 21:21
source share



All Articles