In a simple data table, with a decimal column I am getting different results when using Equals and ==. I'm sure there is a good reason for this, I just cannot find it - can anyone please explain to me why these would be different?
using System.Data; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("amount", typeof(int))); dt.Columns.Add(new DataColumn("code", typeof(string))); DataRow dr = dt.NewRow(); dr["amount"] = 10; dr["code"] = "A"; dt.Rows.Add(dr); dr.AcceptChanges(); bool a = dr["amount", DataRowVersion.Current].Equals(dr["amount", DataRowVersion.Original]); bool b = dr["amount", DataRowVersion.Current] == dr["amount", DataRowVersion.Original]; bool c = dr["code", DataRowVersion.Current].Equals(dr["code", DataRowVersion.Original]); bool d = dr["code", DataRowVersion.Current] == dr["code", DataRowVersion.Original]; } } }
While I fully expect c and d to be equal, notice that a and b are not considered equal when using the == operator. ??