C
C#•3y 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
Pobiega•3y ago
can you show the value of .Planned here?
Macke
MackeOP•3y ago
it's above the bigger screenshot @Pobiega
Pobiega
Pobiega•3y 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
MackeOP•3y ago
hahah sorry, yea i'm kind of scratching my head. yea there must be something i'm doing wrong
TheBoxyBear
TheBoxyBear•3y 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
MackeOP•3y ago
it's 12.52 pm here
TheBoxyBear
TheBoxyBear•3y ago
Planned is for 11:40
Macke
MackeOP•3y 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
TheBoxyBear•3y ago
So even if DateTime.Now advances, it wouldn't change the outcome
Macke
MackeOP•3y 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
TheBoxyBear•3y ago
Does it run the if anyway with a breakpoint? If so, then the debugger is messed up dviperShrug
Macke
MackeOP•3y ago
there's no exception and i'm not expecting there to be one
TheBoxyBear
TheBoxyBear•3y ago
No exception, just if it enters the if block
Macke
MackeOP•3y 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
TheBoxyBear•3y ago
We all make dumb mistakes
Macke
MackeOP•3y ago
quick question, do list indexes start at 0 or 1?

Did you find this page helpful?