Inequality test on boxed types (yes, I did something wrong :-) )

The code:

if e.Row.Item[i, System.Data.DataRowVersion.Current] <> e.Row.Item[i, System.Data.DataRowVersion.Original] then
    //do something

The “Do something” code is always executed.

The values are boxed types:
image

for the first index, I would expect that the values are compared using the Int32 implementation, for the second with the String implementation. But it looks like it is doing the Object implementation that checks if the references are equal. And those references are never equal.

Is this a bug or am I doing something wrong? (as this works in VB and in C# as far as I know).

No, I does not wok in C#.

I see now too where the problem is coming from.

In VB, Object is the dynamic type, so a value boxed into an object is always unboxed when used.
Als, in VB the keyword “Is” and “IsNot” is for reference tests, = and <> for the implemented operator test.

In C# and Oxygene Dynamic is a separate type and there is no difference between a reference or implemented operator test, what means that I have to assign to a dynamic variable first to get the correct behavior.

So the correct code Is (to get what I want):

var current: dynamic := e.Row.Item[i, System.Data.DataRowVersion.Current];
var original: dynamic := e.Row.Item[i, System.Data.DataRowVersion.Original];
if current <> original then
    //do something
1 Like