Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:25:27+00:00 2026-05-24T16:25:27+00:00

I am trying to compare a list AAA that contain Date with a range

  • 0

I am trying to compare a list AAA that contain Date with a range of dates. I want to see if any of the range of date is present in the list or not. If the date is present I copy the list items to another list BBB else I add empty values to the list BBB.

The problem I am having is that with my actual code, is I don`t know how not pass through the false statement of the while loop, till it reaches the end of the comparison.

With the code below, it is passing both the true and false in the while loop, which is falsifying the required result. The result I am obtaining is for every time that is present, I am having the same time as false. In short, lets say the list contains the date 6/5/2010, and the range of date is 4/5/2010 to 7/5/2010. so I will have an item created in the true part and AN ITEM CREATED INTHE FALSE PART, which is wrong. The date present can either be in true or false part. Not both, such that I have two items bing created!

How can I achieve the right result? Any other method or suggetsion please.

My code is as follows:

DateTime StartDate; 
DateTime EndDate;
Datetime tempDate = StartDate;
List<DateTime> dateToEvaluate;

bool TimeIsPresent = false;
foreach (var tempItem in TaskList)
{
    while (EndDate.AddDays(1) != tempDate)
    {
        if (tempItem.Date[0] == tempDate)
        {
            TimeIsPresent = True;
            break;
        }
        else
        {
            if (TimeIsPresent == False)
            {
                if (!(tempDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    dateToEvaluate = new List<DateTime>();
                    dateToEvaluate.Add(tempDate);
                    tempTask.Add(new GroupedTask { ID = null,
                                                   TaskID = null,
                                                   Date = dateToEvaluate });
                 }
             }
         }

         tempDate = tempDate.AddDays(1);
                  }

     if (TimeIsPresent == True)
     {
         tempTask.Add(new GroupedTask { ID = tempItem.ID,
                                        TaskID = tempItem.TaskID,
                                        Date = tempItem.Date });
         TimeIsPresent = false;
     }
 }

let me give you an example. My range of date is as follows: Mon 8 Aug – Sunday 14 Aug.
Now my tasklist is as follows: item1: Date 9Aug, item2: Date 11Aug.

So my tempTask must be as follows:
item1: Date 8 Aug, taskID: null, ID: null,
item2: Date 9 Aug, taskID: 678, ID: 7,
item3: Date 10Aug, taskID: null, ID: null,
item4: Date11 Aug, taskID:890, ID: 34,
item5: Date 12 Aug, taskID: null, ID: null,
item6: Date 13 Aug, taskID: null, ID: null


Second example:

My range of date is as follows: Mon 8 Aug – Sunday 14 Aug.
Now my tasklist is as follows: item1: Date 9Aug, item2: Date 11Aug, item3: Date 14Aug

So my tempTask must be as follows:
item1: Date 8 Aug, taskID: null, ID: null,
item2: Date 9 Aug, taskID: 678, ID: 7,
item3: Date 10Aug, taskID: null, ID: null,
item4: Date11 Aug, taskID:890, ID: 34,
item5: Date 12 Aug, taskID: null, ID: null,
item6: Date 13 Aug, taskID: null, ID: null,
item4: Date14 Aug, taskID:894, ID: 74,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:25:27+00:00Added an answer on May 24, 2026 at 4:25 pm

    I’m not sure what is EndDate, tempDate and some other things in your example. But if you are trying to loop through a DateRange and checking the existence of a particular date, then you could consider the following example:

        static void yourFunction()
        {
            //
            //Some Stuffs
            //
            foreach (var tempItem in TaskList)
            {
                if (DateRange.Contains(tempItem.Date[0]))
                {
                    //Do Task
                }
                else
                {
                    //Do Task
                }
            }
            //
            //Some Stuffs
            //
        }
        public static IEnumerable<DateTime> DateRange
        {
            get
            {
                for (DateTime day = startDate; day < EndDate; day = day.AddDays(1))
                {
                    yield return day;
                }
            }
        } 
    

    Encapsulating a range of dates on a property is the idea of Jon Skeet, I learned it from his book C# in Depth

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to compare two files. I will list the two file content:
I'm trying to find a LINQ expression to compare two list elements. What i
I've been trying to compare the memory footprint between a VB6 application and .Net
I am trying to compare two decimal values in Java script. I have two
I am trying to compare the performance of boost::multi_array to native dynamically allocated arrays,
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to make a make generic select control that I can dynamically add elements
I am trying to compare two lists of string in python. Some of the
I'm trying to compare two strings. When I echo them, they appear to be
I am trying to compare two byte arrays in memory and produce a data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.