C
C#

help

Expression returns false even though it should return true

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

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ How to bind DateTime in query parameter?Hi, any tips how I can pass a DateTime as a query parameter? I'm doing an Http request from one api❔ Foreach loopI am trying to run through my list, but nothing is being printed out, what am I doing wrong? ```cs Calculate obj Age [Answered]**Program** ```cs DateTime dtBirthDate = new DateTime(1971, 2, 23); ``` **Student** ```cs public Dat❔ Removing JSON data from JSON FileHey, I am attempting to remove JSON data from a text file if required (I'm using it as a local datab❔ DateTime Property [Answered]```cs public DateTime DateOfTime { get { return _DateOfTime; } ❔ Database ID not beginning from 1?Hello all, complete noob to .NET here. I have successfully seeded my database with some data in ASP.❔ How can I access a member of a different class in a dictionaryHey! I'm trying to refactor my old JSON serializer code, but I ran into an issue. I can't access a s❔ Does nopcommerce support blazor in. Net 6?I would like to know if blazor server for. Net 6 is supported in nopcommerce In the nopcommerce doc❔ Quickest way to get an async function to run?I have an async function with an await inside and I'm currently using Task.Run to start it, but ther❔ Query won't filterI am trying to filter by one of these two search options, they both show up properly in the network ❔ Should I separate the add and edit page in a web app?Ive always combined the add and edit page since the html is the same in both page. Depending if i ha❔ DI QuestionI have this code for setting up DI in my worker service project https://pastebin.com/6HH5sBAx But wAzure Functions output binding to HTTP request (trigger) and storage queue? [Answered]Here is what I'm looking at. https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindi❔ empty string not being recognized```cs string name = nameHolder.text; if (String.IsNullOrEmpty(name)) { name = "New Save"; }``` IStreaming a csv file to a console app with minimal api-How?Hey Guys got this methode: ``` public string MakeHttpCall() { var watch = new Stopwat❔ for is toughOn sports day, the students compete in the high jump. Write a program that accepts as input the nam❔ EF Core nullability vs API nullability behaviorIn EF Core, nullability of properties is deduced from the nullability of their type. In API's howeve❔ Better way of handling this?```cs switch (syncMessage.type) { case "Obj1": Obj1.HandleUpdate(syncMessage.data); breakMAUI Entry Point - MauiProgram.cs [Answered]Typically when creating a new application, be it Console, WPF, WinForms, or Web, the main entry poin❔ UNITY Vector3 not applying```cs int cPop = Mathf.RoundToInt(((tCity.POP_MIN + tCity.POP_MAX) ?? 0) / 2.0f); //tCit