Данный отчёт сгенерирован 04.04.2023 06:21:13 UTC.
HTML версия (этот сайт) сгенерирован 04.04.2023 06:21:31 UTC.
Коммит: [bfeb65b9] add automatic zip creation 04.04.2023 06:21:13
HTML версия (этот сайт) сгенерирован 04.04.2023 06:21:31 UTC.
Коммит: [bfeb65b9] add automatic zip creation 04.04.2023 06:21:13
Задача: Клас із методом Equals
04.04.2023 06:21:13
Описание: Визначте клас C, де є відкрита ціла властивість X і відкрита властивість Father типу C.
Перекрийте метод Equals для цього класу так, щоб екземпляри класу a та b були еквівалентними,
якщо значення властивостей попарно рівні, тобто. a.X == b.X, і a.Father == b.Father.
04.04.2023 06:21:13
Решений: 23
04.04.2023 06:21:13
Клас із методом Equals
04.04.2023 06:21:13
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(Object obj)
{
if (obj is null)
return false;
if (this.GetType() != obj.GetType())
return false;
C b = (C)obj;
return (this.X == b.X) && (this.Father == b.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C
{
public int X { get; set; }
public C? Father { get; set; }
public override bool Equals(object? obj)
{
if (obj == null)
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
C c = (C)obj;
return X == c.X && Father == c.Father;
}
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
class C : IEquatable< C>
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) => Equals(obj as C);
public bool Equals(C other)
{
if (other is null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return X == other.X && Father == other.Father;
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>this.Equals(obj as C);
public bool Equals(C other)
{
if (other is null){
return false;
}
if (Object.ReferenceEquals(this, other))
{
return true;
}
if (other.GetType()!=this.GetType()){
return false;
}
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode()
{
return (X,Father).GetHashCode();
}
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj)
=> Equals(obj as C);
public bool Equals(C other)
{
if (other == null)
return false;
if (object.ReferenceEquals(other, this))
return true;
if (this.GetType() != other.GetType())
return false;
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode()
{
return this.X + Father?.X ?? 0;
}
}
class C : IEquatable< C>
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object? obj) =>
this.Equals(obj as C);
public bool Equals(C? other)
{
if (other is null)
return false;
if (this.GetType() != other.GetType())
return false;
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) => this.Equals(obj as C);
public bool Equals(C c)
{
if(c == null)
return false;
if (object.ReferenceEquals(this, c))
return true;
if (this.GetType() != c.GetType())
return false;
return X == c.X && Father == c.Father;
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C : IEquatable< C>
{
public int X { get; set; }
public C? Father { get; set; }
public C (int x, C? father)
{
X = x;
Father = father;
}
public C () { }
public override bool Equals(object obj) => Equals(obj as C);
public bool Equals(C? other)
{
if (other is null)
{
return false;
}
if (Object.ReferenceEquals(this, other))
{
return true;
}
if (this.GetType() != other.GetType())
{
return false;
}
return (X == other.X) && (Father == other.Father);
}
public override int GetHashCode() => (X, Father?.X).GetHashCode();
}
public class C
{
public int X { get; set; }
public C Father { get; set; }
public override int GetHashCode() => (X, Father).GetHashCode();
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C c)
{
if (c is null)
{
return false;
}
if (Object.ReferenceEquals(this,c))
{
return true;
}
if (this.GetType() != c.GetType())
{
return false;
}
return (this.X == c.X && this.Father == c.Father);
}
}
class C : IEquatable< C>
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C other)
{
if (other is null)
return false;
if (Object.ReferenceEquals(this, other))
return true;
if (this.GetType() != other.GetType())
return false;
return (X == other.X) && (Father == other.Father);
}
public override int GetHashCode()
{
return HashCode.Combine(X, Father);
}
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public bool Equals(C c)
{
if (c is null || this.GetType() != c.GetType())
{
return false;
}
if (Object.ReferenceEquals(this, c))
{
return true;
}
return (X == c.X) && (Father == c.Father);
}
public override int GetHashCode() => HashCode.Combine(X, Father);
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(Object obj) =>
this.Equals(obj as C);
public bool Equals(C other)
{
if (other is null)
{
return false;
}
if (Object.ReferenceEquals(this, other))
{
return true;
}
if (this.GetType() != other.GetType())
{
return false;
}
return (this.X == other.X) && (this.Father == other.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C : IEquatable< C>
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C? c)
{
if (c is null)
return false;
if (Object.ReferenceEquals(this, c))
return true;
if (this.GetType() != c.GetType())
return false;
return (this.X == c.X && this.Father == c.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C : IEquatable< C>
{
public int X { get; set; }
public C? Father { get; set; }
public C(int x, C father)
{
Father = father;
X = x;
}
public C()
{
Father = null;
X = 0;
}
public bool Equals(C? cObj)
{
bool isObjectNull = ReferenceEquals(null, cObj);
if (isObjectNull) return false;
bool isObjectAnotherType = cObj.GetType() != this.GetType();
if (isObjectAnotherType) return false;
bool areObjectsTheSame = ReferenceEquals(this, cObj);
if (areObjectsTheSame) return true;
return (this.X == cObj.X) && (this.Father == cObj.Father);
}
public override bool Equals(object? obj) => this.Equals(obj as C);
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) => this.Equals(obj as C);
public bool Equals(C c)
{
if(c is null) return false;
if(Object.ReferenceEquals(this, c))
return true;
if(this.GetType() != c.GetType())
return false;
return (X == c.X) && (Father == c.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C
{
public int X{get;set;}
public C Father{get;set;}
public override bool Equals(Object obj)
{
if (obj is null)
{
return false;
}
if (Object.ReferenceEquals(this, obj))
{
return true;
}
if (this.GetType() != obj.GetType())
{
return false;
}
C b = (C)obj;
return (X == b.X) && (Father == b.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
public class C : IEquatable< C>
{
public int X { get; set; }
public C? Father { get; set; }
public C() { }
public C(int x, C? father)
{
X = x;
Father = father;
}
public override bool Equals(object? obj) => this.Equals(obj as C);
public bool Equals(C? other)
{
if (other is null) { return false; }
if (Object.ReferenceEquals(this, other)) { return true; }
if (this.GetType() != other.GetType()) { return false; }
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode() => X.GetHashCode() ^ (Father != null ? Father.GetHashCode() : 28282);
}
public class C : IEquatable< C>
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C c)
{
if (c is null)
{
return false;
}
if (Object.ReferenceEquals(this, c))
{
return true;
}
if (this.GetType() != c.GetType())
{
return false;
}
return (X == c.X) && (Father == c.Father);
}
public override int GetHashCode() => (X, new Guid()).GetHashCode();
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C p)
{
if (p is null)
{
return false;
}
if (Object.ReferenceEquals(this, p))
{
return true;
}
if (this.GetType() != p.GetType())
{
return false;
}
return (X == p.X) && (Father == p.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(Object obj)
{
if (obj == null)
return false;
if (this.GetType() != obj.GetType())
return false;
C objCopy = (C)obj;
if (this.X == objCopy.X && this.Father == objCopy.Father)
return true;
return false;
}
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
class C : IEquatable
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C a)
{
if (a is null) return false;
// Оптимізація для випадку самопорівняння
if (Object.ReferenceEquals(this, a)) return true;
// Різнотипні об'єкти ніколи не еквівалентні
if (this.GetType() != a.GetType()) return false;
// Порівнюємо поля
return (X == a.X) && (Father == a.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
class C
{
public int X { get; set; }
public C Father { get; set; }
public C() {}
public C(int x, C father)
{
X = x;
Father = father;
}
public override bool Equals(object obj)
{
if (obj == null || this.GetType() != obj.GetType())
{
return false;
}
else
{
C c = (C)obj;
return (X == c.X) && (Father == c.Father);
}
}
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
class C {
public int X { get; set; }
public C Father { get; set; }
public override int GetHashCode() {
int hash = this.GetType().GetHashCode();
hash += X.GetHashCode();
if(Father != null)
hash += Father.GetHashCode();
return hash;
}
public override bool Equals(Object _other) {
if((_other == null) || !this.GetType().Equals(_other.GetType()))
return false;
C other = (C) _other;
return this.X == other.X && this.Father == other.Father;
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(Object obj)
{
if (obj is null)
return false;
if (this.GetType() != obj.GetType())
return false;
C b = (C)obj;
return (this.X == b.X) && (this.Father == b.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C? Father { get; set; }
public override bool Equals(object? obj)
{
if (obj == null)
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != this.GetType())
return false;
C c = (C)obj;
return X == c.X && Father == c.Father;
}
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) => Equals(obj as C);
public bool Equals(C other)
{
if (other is null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
if (GetType() != other.GetType())
{
return false;
}
return X == other.X && Father == other.Father;
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>this.Equals(obj as C);
public bool Equals(C other)
{
if (other is null){
return false;
}
if (Object.ReferenceEquals(this, other))
{
return true;
}
if (other.GetType()!=this.GetType()){
return false;
}
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode()
{
return (X,Father).GetHashCode();
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj)
=> Equals(obj as C);
public bool Equals(C other)
{
if (other == null)
return false;
if (object.ReferenceEquals(other, this))
return true;
if (this.GetType() != other.GetType())
return false;
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode()
{
return this.X + Father?.X ?? 0;
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object? obj) =>
this.Equals(obj as C);
public bool Equals(C? other)
{
if (other is null)
return false;
if (this.GetType() != other.GetType())
return false;
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) => this.Equals(obj as C);
public bool Equals(C c)
{
if(c == null)
return false;
if (object.ReferenceEquals(this, c))
return true;
if (this.GetType() != c.GetType())
return false;
return X == c.X && Father == c.Father;
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C? Father { get; set; }
public C (int x, C? father)
{
X = x;
Father = father;
}
public C () { }
public override bool Equals(object obj) => Equals(obj as C);
public bool Equals(C? other)
{
if (other is null)
{
return false;
}
if (Object.ReferenceEquals(this, other))
{
return true;
}
if (this.GetType() != other.GetType())
{
return false;
}
return (X == other.X) && (Father == other.Father);
}
public override int GetHashCode() => (X, Father?.X).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public override int GetHashCode() => (X, Father).GetHashCode();
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C c)
{
if (c is null)
{
return false;
}
if (Object.ReferenceEquals(this,c))
{
return true;
}
if (this.GetType() != c.GetType())
{
return false;
}
return (this.X == c.X && this.Father == c.Father);
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C other)
{
if (other is null)
return false;
if (Object.ReferenceEquals(this, other))
return true;
if (this.GetType() != other.GetType())
return false;
return (X == other.X) && (Father == other.Father);
}
public override int GetHashCode()
{
return HashCode.Combine(X, Father);
}
}
{
public int X { get; set; }
public C Father { get; set; }
public bool Equals(C c)
{
if (c is null || this.GetType() != c.GetType())
{
return false;
}
if (Object.ReferenceEquals(this, c))
{
return true;
}
return (X == c.X) && (Father == c.Father);
}
public override int GetHashCode() => HashCode.Combine(X, Father);
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(Object obj) =>
this.Equals(obj as C);
public bool Equals(C other)
{
if (other is null)
{
return false;
}
if (Object.ReferenceEquals(this, other))
{
return true;
}
if (this.GetType() != other.GetType())
{
return false;
}
return (this.X == other.X) && (this.Father == other.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C? c)
{
if (c is null)
return false;
if (Object.ReferenceEquals(this, c))
return true;
if (this.GetType() != c.GetType())
return false;
return (this.X == c.X && this.Father == c.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C? Father { get; set; }
public C(int x, C father)
{
Father = father;
X = x;
}
public C()
{
Father = null;
X = 0;
}
public bool Equals(C? cObj)
{
bool isObjectNull = ReferenceEquals(null, cObj);
if (isObjectNull) return false;
bool isObjectAnotherType = cObj.GetType() != this.GetType();
if (isObjectAnotherType) return false;
bool areObjectsTheSame = ReferenceEquals(this, cObj);
if (areObjectsTheSame) return true;
return (this.X == cObj.X) && (this.Father == cObj.Father);
}
public override bool Equals(object? obj) => this.Equals(obj as C);
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) => this.Equals(obj as C);
public bool Equals(C c)
{
if(c is null) return false;
if(Object.ReferenceEquals(this, c))
return true;
if(this.GetType() != c.GetType())
return false;
return (X == c.X) && (Father == c.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X{get;set;}
public C Father{get;set;}
public override bool Equals(Object obj)
{
if (obj is null)
{
return false;
}
if (Object.ReferenceEquals(this, obj))
{
return true;
}
if (this.GetType() != obj.GetType())
{
return false;
}
C b = (C)obj;
return (X == b.X) && (Father == b.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C? Father { get; set; }
public C() { }
public C(int x, C? father)
{
X = x;
Father = father;
}
public override bool Equals(object? obj) => this.Equals(obj as C);
public bool Equals(C? other)
{
if (other is null) { return false; }
if (Object.ReferenceEquals(this, other)) { return true; }
if (this.GetType() != other.GetType()) { return false; }
return this.X == other.X && this.Father == other.Father;
}
public override int GetHashCode() => X.GetHashCode() ^ (Father != null ? Father.GetHashCode() : 28282);
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C c)
{
if (c is null)
{
return false;
}
if (Object.ReferenceEquals(this, c))
{
return true;
}
if (this.GetType() != c.GetType())
{
return false;
}
return (X == c.X) && (Father == c.Father);
}
public override int GetHashCode() => (X, new Guid()).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C p)
{
if (p is null)
{
return false;
}
if (Object.ReferenceEquals(this, p))
{
return true;
}
if (this.GetType() != p.GetType())
{
return false;
}
return (X == p.X) && (Father == p.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(Object obj)
{
if (obj == null)
return false;
if (this.GetType() != obj.GetType())
return false;
C objCopy = (C)obj;
if (this.X == objCopy.X && this.Father == objCopy.Father)
return true;
return false;
}
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
{
public int X { get; set; }
public C Father { get; set; }
public override bool Equals(object obj) =>
this.Equals(obj as C);
public bool Equals(C a)
{
if (a is null) return false;
// Оптимізація для випадку самопорівняння
if (Object.ReferenceEquals(this, a)) return true;
// Різнотипні об'єкти ніколи не еквівалентні
if (this.GetType() != a.GetType()) return false;
// Порівнюємо поля
return (X == a.X) && (Father == a.Father);
}
public override int GetHashCode() => (X, Father).GetHashCode();
}
{
public int X { get; set; }
public C Father { get; set; }
public C() {}
public C(int x, C father)
{
X = x;
Father = father;
}
public override bool Equals(object obj)
{
if (obj == null || this.GetType() != obj.GetType())
{
return false;
}
else
{
C c = (C)obj;
return (X == c.X) && (Father == c.Father);
}
}
public override int GetHashCode()
{
return (X, Father).GetHashCode();
}
}
public int X { get; set; }
public C Father { get; set; }
public override int GetHashCode() {
int hash = this.GetType().GetHashCode();
hash += X.GetHashCode();
if(Father != null)
hash += Father.GetHashCode();
return hash;
}
public override bool Equals(Object _other) {
if((_other == null) || !this.GetType().Equals(_other.GetType()))
return false;
C other = (C) _other;
return this.X == other.X && this.Father == other.Father;
}
}