为什么方法返回false?

Dim*_*zyr -1 c#

此方法返回false.我不明白为什么

private bool SomeMethod()
{
    return new byte[0] == new byte[0];
}
Run Code Online (Sandbox Code Playgroud)

Ste*_*eve 5

您正在创建两个字节数组.这两个数组具有不同的内存地址,并且比较不同的地址返回false

bool result = (new byte[0] == new byte[0]);
Console.WriteLine(result);

......
IL_0001:  ldc.i4.0                    // zero int for size in the evaluation stack
IL_0002:  newarr      System.Byte     // create an array of zero bytes 
IL_0007:  ldc.i4.0                    // zero int for size in the evaluation stack
IL_0008:  newarr      System.Byte     // create another array of zero bytes
IL_000D:  ceq                         // compare the address of the two arrays
IL_000F:  stloc.0     // result
IL_0010:  ldloc.0     // result
IL_0011:  call        System.Console.WriteLine
Run Code Online (Sandbox Code Playgroud)