有一个简单的类:
namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
Test test = null;
int? t;
t = test?.i; // in this place the overloaded method "operator! =" is NOT called
if (test != null) // in this place the overloaded method "operator! =" is called
{
t = test.i;
}
}
}
public class Test
{
public int i = 5;
public override bool Equals(object obj)
{
return true;
}
public static bool operator ==(Test test1, Test …Run Code Online (Sandbox Code Playgroud) c# ×1