외부 나는 다음과 같은 시나리오가 :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