.NET Dictionaries have same keys and values, but aren't “equal”

前端 未结 6 1278
旧时难觅i
旧时难觅i 2021-01-17 08:48

This test fails:

using Microsoft.VisualStudio.TestTools.UnitTesting;        

[TestMethod()]
        public void dictEqualTest() {
            IDictionary<         


        
6条回答
  •  不要未来只要你来
    2021-01-17 09:16

    You are completely not understanding how reference types work.

    Dictionary does not override object.Equals(). Thus, it uses reference equality - basically, if both references are pointing to the same instance, they're equal, otherwise they aren't.

提交回复
热议问题