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 7871741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:59:50+00:00 2026-06-03T01:59:50+00:00

I have seen several examples of how to compare in Linq using the Except

  • 0

I have seen several examples of how to compare in Linq using the Except operator and comparison, but they all seemed to show how it is done with two simple Types or one simple Type and one complex. I have two List of different types, I need to select a result based on a child property and then select another group where the properties match but a DateTime is newer. Can anyone help me through this?

        public class Parent
        {
            public List<Child> ChildList;
        }

        public class Child
        {
            public string FoodChoice;
            public DateTime FoodPick;
        }


        public class Food
        {
            public string FoodName;
            public DateTime FoodPick;
        }

        public void FoodStuff
    {
       var parent = new Parent();
     var childList = new List<Child>();
childList.Add( new Child {FoodChoice="a",DateTime=..... 
childList.Add( new Child {FoodChoice="b",DateTime=..... 
childList.Add( new Child {FoodChoice="c",DateTime=..... 
parent.ChildList = childList;
        var foodList = new List<Food>();
        foodList.Add......
        var childrenWithNoMatchingFoodChoices = from ufu in Parent.ChildList where !Parent.ChildList.Contains ( foodList.FoodName )
        var childrenWithMatchingFoodChoicesButWithNewerFoodPick = from foo in Parent.ChildList where Parent.ChildList.FoodPick > foodList.FoodPick
    }

I am trying to figure out how to get a List<Child> for childrenWithNoMatchingFoodChoices .
I am trying to figure out how to get a List<Child> for childrenWithMatchingFoodChoicesButWithNewerFoodPick

Help? Using .NET Framework 4.0.

Thanks.

  • 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-06-03T01:59:53+00:00Added an answer on June 3, 2026 at 1:59 am

    To get a list of children where FoodChoice is not on the foodList I would use this query:

    var childrenNoMatch = parent.ChildList
                     .Where(ch => !foodList.Any(f => f.FoodName == ch.FoodChoice));
    

    Then I would try something along these lines:

        var childrenMatch = parent.ChildList.Except(childrenNoMatch);
    
        //childrenWithMatchingFoodChoicesButWithNewerFoodPick
        var moreRecent = from ch in childrenMatch
                 let food = foodList.First(f => f.FoodName == ch.FoodChoice)
                 where DateTime.Compare(ch.FoodPick, food.FoodPick) == 1
                 select ch
    

    It’s not tested though.

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

Sidebar

Related Questions

I have seen several examples using <a href=<spring:url value='/about/' /> >About </a> I try
I've seen several examples of many to many relationships in EF using code-first, but
I have seen several examples on how to find children, etc but for some
I have seen several questions with people asking about the same problem but none
I have seen several posts similar to this but none with a strait forward
I've seen several examples of how to display a line count, and have tried
I've seen several examples of code like this: if not someobj: #do something But
I've seen several examples on here of something close to what I'm asking, but
Recalling this post enumerating several problems of using singletons and having seen several examples
I want to show the weather in my GWT application. I have seen several

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.