473,473 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic Casting in CSharp

Hi,

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

Table.Rows[i][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.
Jun 27 '08 #1
2 1316
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[i][j].Equals( oleDbDataReader.GetValue(i) )

Glenn

<Ma*************@gmail.comwrote in message
news:48**********************************@m73g2000 hsh.googlegroups.com...
Hi,

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

Table.Rows[i][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.

Jun 27 '08 #2
On May 14, 10:34 am, Magnus.Morab...@gmail.com wrote:
I have the following which is giving me false when I expected true -

Table.Rows[i][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[i][j],
oleDbDataReader.GetValue(i))

Jon
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Radde | last post by:
HI, Are ther any pitfalls for dynamic cast in type safe downcasting..
3
by: Dusty | last post by:
How can I make my dynamic array ? I'm curios how the ArrayList does it. For example: string s = new string; and later I want to expand this array to more than 16 elements without loosing...
3
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example...
1
by: Alex | last post by:
Is that "as" returns null if failed to cast, doesn't throw an exception, so you can check the reference for null afterwards. straight casting will throw an InvalidCastException exception.
3
by: Guy Harwood | last post by:
Hi, I have designed a textbox that inherits from the System.Windows.Forms.Textbox control. when the control is readonly the back color changes to a light blue to indicate that it is frozen. ...
4
by: Tamir Khason | last post by:
Is it possible (as was in VB - CallByName) to call function which name was generated. Example: private static void DS_function() { } private static void FD_function() {
2
by: Zac | last post by:
Alright anyone who has 2c throw it in... I am working through a custom xml serializer and have come upon a conundrum, given our class design. The interface implemented on the base class (base...
2
by: babylon | last post by:
I have an enum public enum MyEnum : int { X, Y } I have to do int a = (int) MyEnum.X; can i overload the operator or other means to do something like
2
by: Martin Hart - Memory Soft, S.L. | last post by:
Hi all: I still very new to the .NET world and don't know if what I am asking is due to an over-imaginative imagination or the fact that I have read too many fiction books!! Let me show you a...
6
by: DaTurk | last post by:
Hi, I have three interfaces lets call them parent, child-A, and child-B. I want to have one variable, that can be either child-A, or child-B at run time. I just can't seem to figure out how to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.