Monday 24 February 2014

Boxing issues in C# - Brain Dump 1

I'm going through my emails collecting all the interesting stuff that I have accrued over the past year or so, most of it not mine and dumping it here in various posts, I could just keep the pst file but ....

       [TestMethod]
       public void TestMethod1()
        {
            decimal d1 = 20;
            decimal d2 = 20;

            Assert.IsTrue(compare (d1, d2));
        } 

        private bool compare (object o1, object o2)
        {
            return o1 == o2;
        }

The test above will fail, should use this instead:

        private bool compare (object o1, object o2)
        {
            return o1.Equals(o2);
        }

No comments:

Post a Comment