static bool Compare0() { return new byte() == new byte(); } static bool Compare1() { return new byte[0] == new byte[0]; } static void Main() { Console.WriteLine(Compare0()); Console.WriteLine(Compare1()); Console.ReadKey(); } 

Why Compare0() return True , and Compare0() returns False ?

    1 answer 1

    The new byte() construct creates an instance of the byte type, initialized to zero. byte is a structure, and therefore it is a significant type. By default, all significant types are compared by value. Since two instances are initialized to the same value, Compare0() returns True .

    The new byte[0] construct creates an empty byte array. An array is a reference type. By default, instances of reference types are equal only if their references are equal, i.e. instances point to the same object. Since two instances of an array are two different objects in memory, Compare1() returns False .

    You can read more about relevant and reference types in this answer .