널 (null)에 대한 검사 : 같은 현재는 NullReferenceException이 발생합니다,IEquatable - 재정 같음 - 나는 이렇게 <code>IEquatable<T></code> 방법이
public bool Equals(TravelOptions other)
{
if (other == null) return false;
return
this.OutTravelType.Equals(other.OutTravelType) & //enum
this.BackTravelType.Equals(other.BackTravelType) & //enum
this.OutTravelPointID.Equals(other.OutTravelPointID) & //int
this.BackTravelPointID.Equals(other.BackTravelPointID) & //int
this.OutTerminal.Equals(other.OutTerminal) & //string
this.BackTerminal.Equals(other.BackTerminal) & //string
this.OutTime.Equals(other.OutTime) & //string :(
this.BackTime.Equals(other.BackTime) & //string
this.Checkin.Equals(other.Checkin) & //int
this.OutFree.Equals(other.OutFree) & //bool
this.BackFree.Equals(other.BackFree); //bool
}
하지만 내가 거기에 다양한 비트의 널위한 몇 가지 검사를 추가하기 만하면됩니다를 그렇게하는 것이 교활한 방법일까요? 그래서 심하게 엉망이되지는 않습니까? out 및 back 여행 유형은 enum이며 항상 먼저 설정되어 있으므로 먼저 확인해야합니다. 바깥 쪽과 뒤쪽 바깥 쪽은 bool이고, travelpoints는 int이며, 나머지는 모두 문자열입니다. 그 일을하는 몇 가지 속기 방법이 없다면 널 (null)을 검사해야하기 시작하면 지저분해질 것 같아?
감사
답장을 보내 주셔서 감사합니다. 나는 bitwise로 짧은 순환을하고 있다고 생각했지만, 왜 그런지 == 작동하는지, 그리고 Equals (왜 나던가요?)라고 설명 할 수 있습니까? 감사합니다. – nat
@nat :'==' 두 개의 인수로 정적 메소드를 호출하는 것과 같습니다. 반면 * 인스턴스 * 메소드를 호출하면 대상 참조가 null 인 경우 실패합니다. –