class OperatorOverloading
{
static bool AreReferencesEqual<T>(T first, T second)
where T : class
{
return first == second;
}
static void Main()
{
string name = "Jon";
string intro1 = "My name is " + name;
string intro2 = "My name is " + name;
Console.WriteLine(intro1 == intro2);
Console.WriteLine(AreReferencesEqual(intro1, intro2));
}
}
static bool AreReferencesEqual<T>(T first, T second)
where T : class
{
return first == second;
}
比较引用 执行时不会重载 传入的可能是 ojbect类型
Console.WriteLine(intro1 == intro2);
用string 重载 == 操作符进行比较 执行结果 true
输入
string name = "Jon";
string intro1 = "My name is " + name;
string intro2 = "My name is " + name;
输出
True
False