C
C#2y ago
Macke

Expression returns false even though it should return true

Hi, I'm trying to check if a date is before now or after NOW. While debugging i can see that the expression doesn't return true even though it should.
16 Replies
Pobiega
Pobiega2y ago
can you show the value of .Planned here?
Macke
Macke2y ago
it's above the bigger screenshot @Pobiega
Pobiega
Pobiega2y ago
right, really hard to see 😄 well, thats... very weird. I've never in my 20 years of programming encountered an actual "true is false" bug so I doubt we are seeing one here either
Macke
Macke2y ago
hahah sorry, yea i'm kind of scratching my head. yea there must be something i'm doing wrong
TheBoxyBear
TheBoxyBear2y ago
There was another post yesterdya where the debugger showed "" != "" so could be a similar thing here? Assuming it's 10:52 or earlier where op lives then it doesn't make sense
Macke
Macke2y ago
it's 12.52 pm here
TheBoxyBear
TheBoxyBear2y ago
Planned is for 11:40
Macke
Macke2y ago
yea I guess i'll explain i have a list with objects and if time has passed past the .Planned property i want to remove it from the list
TheBoxyBear
TheBoxyBear2y ago
So even if DateTime.Now advances, it wouldn't change the outcome
Macke
Macke2y ago
So i have objects i need to remove that are tomorrow and before the time that is now
List<int> indexestoremove = new List<int>();
List<FlightData> data = GetData();
if(data == null)
{
return null;
}
for (int y = 0; y < data.Count; y++)
{
if (data[y].Planned < DateTime.Now)
{
if (data[y].Estimated == null || data[y].Estimated < DateTime.Now || data[y].Planned.Date > DateTime.Now)
{
indexestoremove.Add(y);
}

}
}

foreach (var item in indexestoremove)
{
data.RemoveAt(item);
}
List<int> indexestoremove = new List<int>();
List<FlightData> data = GetData();
if(data == null)
{
return null;
}
for (int y = 0; y < data.Count; y++)
{
if (data[y].Planned < DateTime.Now)
{
if (data[y].Estimated == null || data[y].Estimated < DateTime.Now || data[y].Planned.Date > DateTime.Now)
{
indexestoremove.Add(y);
}

}
}

foreach (var item in indexestoremove)
{
data.RemoveAt(item);
}
TheBoxyBear
TheBoxyBear2y ago
Does it run the if anyway with a breakpoint? If so, then the debugger is messed up dviperShrug
Macke
Macke2y ago
there's no exception and i'm not expecting there to be one
TheBoxyBear
TheBoxyBear2y ago
No exception, just if it enters the if block
Macke
Macke2y ago
i'll check one sec oh my god i just saw it i'm so stupid It removes the objects that are before now but not after today But it's because I'm first checking if it's less than now and then checking if it's more than today so since it's not less than now it's never gonna reach the second if block it's at moments like this i'm wondering if i really should be doing this lol
TheBoxyBear
TheBoxyBear2y ago
We all make dumb mistakes
Macke
Macke2y ago
quick question, do list indexes start at 0 or 1?