Page 1 of 1

object to long datatype converion

Posted: Mon Aug 09, 2010 5:52 am
by Vikas
Hi

I need to cconvert object datatype to long.

I am using the switch statement like this.

Switch(
DownloadTourMaster.CalculateExpectedDuration=0,
0,
DownloadTourMaster.CalculateExpectedDuration > 0,
DownloadTourMaster.TourCount + DownloadTourMaster.MissedCount
)

In above code DownloadTourMaster.CalculateExpectedDuration is the object datatype. Its showing error as runtime that can't assign object or int to > operator.

Please suggest me. Its very urgent.

Thanks
Vikas

object to long datatype converion

Posted: Mon Aug 09, 2010 7:03 am
by Alex K.
Hello,

You make incorrect comparison of DateTime и Long.
If you wish to compare the field of the DateTime type, then you need to either compare with some default value
(for example 01.01.1900:

Code: Select all

Switch( DownloadTourMaster.CalculateExpectedDuration==DateTime.Parse("01.01.1900"), 0,
 DownloadTourMaster.CalculateExpectedDuration >DateTime.Parse("01.01.1900"), DownloadTourMaster.TourCount + DownloadTourMaster.MissedCount))
or to calculate the amount in days (hours, minutes) and compare with it (Long and Long).

Thank you.

object to long datatype converion

Posted: Mon Aug 09, 2010 8:08 am
by Alex K.
Hello,

You cannot compare different types (in your case the object and long types) This is one of the requirements of the .NET (severe data typification).
You must use the reduction of types.

You may use the following expression:
Switch((long)DownloadTourMaster.CalculateExpectedDuration==0,0,
(long)DownloadTourMaster.CalculateExpectedDuration > 0, DownloadTourMaster.TourCount + DownloadTourMaster.MissedCount)

Thank you.

object to long datatype converion

Posted: Tue Aug 10, 2010 12:38 am
by Vikas
Hello Aleksey,

I found the solution. Thanks a lot.


Thanks
Vikas

object to long datatype converion

Posted: Tue Aug 10, 2010 1:11 am
by Alex K.
Ok! Thank you.