Brunet.Collections.CacheKey.Equals C# (CSharp) Метод

Equals() публичный Метод

public Equals ( object o ) : bool
o object
Результат bool
  public override bool Equals(object o) {
    if( this == o ) { return true; }
    CacheKey other = o as CacheKey;
    if( other == null ) { return false; }
    if( Objects.Length != other.Objects.Length ) { return false; }
    int i = 0;
    bool same = true;
    while( same && i < Objects.Length ) {
      if( Objects[i] != null ) {
        same = Objects[i].Equals( other.Objects[i] );
      }
      else {
        same = (other.Objects[i] == null);
      }
      i++;
    }
    return same;
  }
}

Usage Example

Пример #1
0
        public void CacheKeyTest()
        {
            CacheKey test1 = new CacheKey("hello", "this", "is", "a", "test");
            CacheKey test2 = new CacheKey("hello", "this", "is", "a", "test");
            CacheKey test3 = new CacheKey("hello", "this", "is", "not", "a", "test");
            CacheKey test4 = new CacheKey("hello", "this", "is", "a different", "test");

            Assert.AreEqual(test1.GetHashCode(), test2.GetHashCode(), "CacheKey Hashcode equality");
            Assert.AreEqual(test1, test2, "CacheKey equality");
            Assert.IsFalse(test1.Equals(test3), "CacheKey non-equality");
            Assert.IsFalse(test2.Equals(test3), "CacheKey non-equality");
            Assert.IsFalse(test1.Equals(test4), "CacheKey non-equality");
            Assert.IsFalse(test2.Equals(test4), "CacheKey non-equality");
            Assert.IsFalse(test3.Equals(test4), "CacheKey non-equality");
        }
All Usage Examples Of Brunet.Collections.CacheKey::Equals