Given the following class 鑑於如下課程 ide
public class Foo { public int FooId { get; set; } public string FooName { get; set; } public override bool Equals(object obj) { Foo fooItem = obj as Foo; if (fooItem == null) { return false; } return fooItem.FooId == this.FooId; } public override int GetHashCode() { // Which is preferred? return base.GetHashCode(); //return this.FooId.GetHashCode(); } }
I have overridden the Equals
method because Foo
represent a row for the Foo
s table. 我已經覆蓋了Equals
方法,由於Foo
表明的一排Foo
桌上。 Which is the preferred method for overriding the GetHashCode
? 重寫GetHashCode
的首選方法是? this
Why is it important to override GetHashCode
? 重寫GetHashCode
爲何很重要? spa