ものがたり(旧)

atsushieno.hatenablog.com に続く

DataRowComparer weird behavior

のっけから躓かされているような。

http://msdn.microsoft.com/en-us/library/bb908065.aspx

The GetHashCode method is the value-based comparison implementation of the GetHashCode method.

と書いてあるのだけど

DataSet ds = new DataSet ();
DataTable dt = new DataTable ("MyTable");
ds.Tables.Add (dt);
dt.Columns.Add ("col1");
dt.Columns.Add ("col2");
DataRow r1 = dt.Rows.Add (new object [] {"foo", "bar"});
DataRow r2 = dt.Rows.Add (new object [] {"foo", "bar"});
ds.AcceptChanges ();
DataRowComparer<DataRow> c = DataRowComparer.Default;
Assert.IsTrue (c.GetHashCode (r1) == c.GetHashCode (r2), "#1");
r2 ["col2"] = "baz";
r2.AcceptChanges ();
// .NET fails here
Assert.IsFalse (c.GetHashCode (r1) == c.GetHashCode (r2), "#2");
DataRow r3 = dt.Rows.Add (new object [] {"foo", "baz"});
// .NET fails here
Assert.IsFalse (c.GetHashCode (r1) == c.GetHashCode (r3), "#3");

何を渡しても同じhashが帰ってきているみたい。なんで??