R
R. Kaushik
I am posting the code snippet here. It seems to me that the ?:
Operator is not behaving properly. It seems like it is a bug:
TimeSpan ts1, ts2;
float dayHours = 0;
ts1 = (some_datetime_variable_1);
ts2 = (some_datetime_variable_2);
// ****************** Working Code *************************
// This computes dayHours correctly
if(ts1.TotalHours > 0)
dayHours = (float)ts1.TotalHours;
if(ts2.TotalHours > 0)
dayHours += (float)ts2.TotalHours;
// ****************** Working Code *************************
// ****************** Non-Working Code *************************
// This does not add the portion after + sign
dayHours = (float)(ts1.TotalHours > 0 ? ts1.TotalHours : 0 +
ts2.TotalHours > 0 ? ts2.TotalHours : 0);
// ****************** Non-Working Code *************************
As commented above, I am trying to condense the working code to one
line using ? operator but the one line non-working code dows not add
the variable after + sign. For example, if ts1.TotalHours is 4 and
ts2.TotalHours is 3, the dayHours is computed as 4. Though, I can use
the working code, which takes four lines but it is something I am
doing wrong here or it is a bug in .NET Framework?
Thank you for your time for looking at my post and would appreciate
your responses.
R. Kaushik
Operator is not behaving properly. It seems like it is a bug:
TimeSpan ts1, ts2;
float dayHours = 0;
ts1 = (some_datetime_variable_1);
ts2 = (some_datetime_variable_2);
// ****************** Working Code *************************
// This computes dayHours correctly
if(ts1.TotalHours > 0)
dayHours = (float)ts1.TotalHours;
if(ts2.TotalHours > 0)
dayHours += (float)ts2.TotalHours;
// ****************** Working Code *************************
// ****************** Non-Working Code *************************
// This does not add the portion after + sign
dayHours = (float)(ts1.TotalHours > 0 ? ts1.TotalHours : 0 +
ts2.TotalHours > 0 ? ts2.TotalHours : 0);
// ****************** Non-Working Code *************************
As commented above, I am trying to condense the working code to one
line using ? operator but the one line non-working code dows not add
the variable after + sign. For example, if ts1.TotalHours is 4 and
ts2.TotalHours is 3, the dayHours is computed as 4. Though, I can use
the working code, which takes four lines but it is something I am
doing wrong here or it is a bug in .NET Framework?
Thank you for your time for looking at my post and would appreciate
your responses.
R. Kaushik