Here I will post problems I and my colleagues met and solutions we found.

Wednesday, February 23, 2005

Numbers like objects

Sometime it is very convinient that object can be container for anything, including number. But...

I understand how why it happens but I still don't like it. Here is what I am talking about:

int i16 = 2;
int i32 = 2;
object obj16 = 2;
object obj32 = 2;
bool b;
b = (i16 == i32);
MessageBox.Show("i16 == i32 " + b.ToString()); // result is true
b = (obj16 == obj32);
MessageBox.Show("obj16 == obj32 " + b.ToString()); // result is false

It made me think I am getting crazy once. DataRow returns your result as object. And actual type may depend on type of column in table in database. In my case one column was declared as int, another one as shortint. In DevExpress (www.devexpress.com) grid I tried to apply particular style depending on data value. And value to compare was stored as object. Well, you figured out what happened then...

No comments: