之外我有以下情形:C#重載==操作符類
public class SomeClass {
// Have some other data members as well
public int i ;
}
public class TestClass {
public bool SomeFunction() {
SomeClass a = new SomeClass();
SomeClass b = new SomeClass();
if (a == b) // this is where I am getting compile error
return true;
return false;
}
public static bool operator==(SomeClass a, SomeClass b) {
if (a.i == b.i)
return true;
// compare some other members as well
return false;
}
}
這是可能在C#中實現?
感謝您的幫助!
爲什麼你想在課堂上做到這一點? –
因爲在實際的代碼中,類在上面的例子「SomeClass」,是別人的,我想驗證它 – test123