123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SmartCoalApplication.Base
- {
- [Serializable]
- public struct Pair<T, U>
- {
- private T first;
- private U second;
- public T First
- {
- get
- {
- return this.first;
- }
- }
- public U Second
- {
- get
- {
- return this.second;
- }
- }
- public override int GetHashCode()
- {
- int firstHash;
- int secondHash;
- if (object.ReferenceEquals(this.first, null))
- {
- firstHash = 0;
- }
- else
- {
- firstHash = this.first.GetHashCode();
- }
- if (object.ReferenceEquals(this.second, null))
- {
- secondHash = 0;
- }
- else
- {
- secondHash = this.second.GetHashCode();
- }
- return firstHash ^ secondHash;
- }
- public override bool Equals(object obj)
- {
- return ((obj != null) && (obj is Pair<T, U>) && (this == (Pair<T, U>)obj));
- }
- public static bool operator ==(Pair<T, U> lhs, Pair<T, U> rhs)
- {
- bool firstEqual;
- bool secondEqual;
- if (object.ReferenceEquals(lhs.First, null) && object.ReferenceEquals(rhs.First, null))
- {
- firstEqual = true;
- }
- else if (object.ReferenceEquals(lhs.First, null) || object.ReferenceEquals(rhs.First, null))
- {
- firstEqual = false;
- }
- else
- {
- firstEqual = lhs.First.Equals(rhs.First);
- }
- if (object.ReferenceEquals(lhs.Second, null) && object.ReferenceEquals(rhs.Second, null))
- {
- secondEqual = true;
- }
- else if (object.ReferenceEquals(lhs.Second, null) || object.ReferenceEquals(rhs.Second, null))
- {
- secondEqual = false;
- }
- else
- {
- secondEqual = lhs.Second.Equals(rhs.Second);
- }
- return firstEqual && secondEqual;
- }
- public static bool operator !=(Pair<T, U> lhs, Pair<T, U> rhs)
- {
- return !(lhs == rhs);
- }
- public Pair(T first, U second)
- {
- this.first = first;
- this.second = second;
- }
- }
- }
|