mercredi 17 juillet 2019

== operator using reflection

Objects comparison after using reflection

var a = new A
   {
      a = "aa",
      b = 1
   };

   var b = new A { 
      a = "aa",
      b = 2
   };

   Type type = typeof(A);

   object old = type.GetProperty("a").GetValue(a);
   object Oldold = type.GetProperty("a").GetValue(b);

   int one = 1;
   int oneOne = 1;

   object oneO = one;
   object oneOneO = oneOne


   // old == Oldold  - true
   // one == oneOne - true
   // oneO == oneOneO - false
}

I would expect that oneO == oneOneO is true. Can someone explain me what is going on here?





Aucun commentaire:

Enregistrer un commentaire