Dynamic Casting in CSharp

  • Thread starter Thread starter Magnus.Moraberg
  • Start date Start date
M

Magnus.Moraberg

Hi,

I have the following which is giving me false when I expected true -

Table.Rows[j] == oleDbDataReader.GetValue(i)

oleDbDataReader.GetValue(i) is of type object so I need to cast it to
its correct type before doing the comparison, but how do I do that?

Thanks,

Barry.
 
The following may work, but I'd double check the MSDN docs so you understand
the way the Object.Equals works for reference and value types.

Table.Rows[j].Equals( oleDbDataReader.GetValue(i) )

Glenn
 
I have the following which is giving me false when I expected true -

Table.Rows[j] == oleDbDataReader.GetValue(i)

oleDbDataReader.GetValue(i) is of type object so I need to cast it to
its correct type before doing the comparison, but how do I do that?


Casts give the *compiler* more information. If you don't know that
information at compile-time, you basically can't help the compiler.

I'd suggest using object.Equals(Table.Rows[j],
oleDbDataReader.GetValue(i))

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top