'True' in VB.Net vs C#.Net

Mike_R

Well-known member
Joined
Oct 20, 2003
Messages
316
Location
NYC
It is my understanding that C# and VB have been made essentially 98% compatible, maybe 100% compatible with each other... But one issue sticks out with me...

If a Boolean value or expression returning True coerces to -1 in VB and +1 in C#, how does this work??

Ive tested VB.Net and confirmed that
Code:
 MessageBox.Show(CLng(True).ToString)
returns -1, as it did in VB 6.0...

But I dont have VS.Net, so I cant test it in C... Can someone let me know how C#.Net handles this? And how any discrepancy is rectified??

Thanks in advance :),
Mike
 
Originally posted by Mike_R
It is my understanding that C# and VB have been made essentially 98% compatible, maybe 100% compatible with each other... But one issue sticks out with me...

If a Boolean value or expression returning True coerces to -1 in VB and +1 in C#, how does this work??

Ive tested VB.Net and confirmed that
Code:
 MessageBox.Show(CLng(True).ToString)
returns -1, as it did in VB 6.0...

But I dont have VS.Net, so I cant test it in C... Can someone let me know how C#.Net handles this? And how any discrepancy is rectified??

Thanks in advance :),
Mike

I THINK that 0 is false, and everything else is true.
 
Dont use the old conversion methods of VB6, ones such as
CLng, CStr, CDbl, etc. Instead, use the shared methods of the
Convert class.

Code:
MessageBox.Show(Convert.ToInt32(True).ToString())
 
Can you point me about where all old functions reside in? Just to be aware of em, cos im afraid that ill use them.
 
Well the conversion functions mentioned above are not actually
in the framework, theyre VB-specific keywords. As a general
rule, dont use any VB6 functions. Anything with the same name
as VB6 is probably part of the "Visual Basic Run-Time Library
Members", which you should stay away from. Yes, it takes some
getting used to, but yes, it helps in the end.
 
Back
Top