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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:07:16+00:00 2026-06-08T15:07:16+00:00

So I am abit stuck on a linq statement below, public void ReturnHire(string carregistration,

  • 0

So I am abit stuck on a linq statement below,

        public void ReturnHire(string carregistration, string hirefromdate, string hiretodate)
        {
            var result = customermembers.Where(c => c.CustomerCarType.Where(n => String.Equals(n.CarRegistration, carregistration)).FirstOrDefault(); // this line
            if (result != null)
            {
                customermembers.ForEach(c => c.CustomerHireDate.RemoveAll(cs => cs.HireFromDate == hirefromdate && cs.HireToDate == hiretodate));
                customermembers.ForEach(c => c.CustomerCarType.RemoveAll(cs => cs.CarRegistration == carregistration));
            }
        }

My xml looks like this:

<ArrayOfCustomer>
    <Customer>
        <CustomerID>1</CustomerID>
        <FirstName>G</FirstName>
        <LastName>Graam</LastName>
        <Age>27</Age>
        <CustomerHireDate>
            <HireDate>
                <HireFromDate>15.07.2012</HireFromDate>
                <HireToDate>29.07.2012</HireToDate>
            </HireDate>
        </CustomerHireDate>
        <CustomerCarType>
            <CarType>
                <CarRegistration>IAWB-OOTO</CarRegistration>
            </CarType>
        </CustomerCarType>
    </Customer>
</ArrayOfCustomer>

On my client side the customer is to “return” the vehicle, for me this is basically just removing the hire to and from dates and removing the registration number from within the customer. But here is the catch I have to do this deletion with just the registration number so I was trying to do a where within a where claus but it says I cant implcitly convert CarType to bool.

My web service has these lists:

        List<Customer> customermembers = new List<Customer>();
        List<HireDate> hiredates = new List<HireDate>();
        List<CarType> cartypes = new List<CarType>();

I just thought customermembers where customer car type where rehistration number equals mystring would have been fine?

  • 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-08T15:07:17+00:00Added an answer on June 8, 2026 at 3:07 pm

    Since you don’t actually use result in your if block, you could do this:

        public void ReturnHire(string carregistration, string hirefromdate, string hiretodate) 
        { 
            if (customermembers.Any(c => c.CustomerCarType.Any(n => String.Equals(n.CarRegistration, carregistration)))
            { 
                customermembers.ForEach(c => c.CustomerHireDate.RemoveAll(cs => cs.HireFromDate == hirefromdate && cs.HireToDate == hiretodate)); 
                customermembers.ForEach(c => c.CustomerCarType.RemoveAll(cs => cs.CarRegistration == carregistration)); 
            } 
        } 
    

    Any returns true if there is at least one element that satisfies the predicate.

    This is not terribly efficient, however, since you’re iterating the list three times; you should iterate it just once. I would post an example, but I think there’s a bug in your code and I don’t want to repeat it. Consider separate customers with separate registrations with the same hirefromdate and hiretodate. Your code would remove the CustomerHireDate from the customer who did not yet return the car.

    However, you may well have intended to use result in the if block, which should fix the bug:

        public void ReturnHire(string carregistration, string hirefromdate, string hiretodate) 
        { 
            var result = customermembers.Where(c => c.CustomerCarType.Any(n => String.Equals(n.CarRegistration, carregistration));
            foreach (var customermember in result)
            { 
                customermember.CustomerHireDate.RemoveAll(cs => cs.HireFromDate == hirefromdate && cs.HireToDate == hiretodate); 
                customermember.CustomerCarType.RemoveAll(cs => cs.CarRegistration == carregistration); 
            } 
        }
    

    Remember that Where does not change the original collection, so you need to iterate over result in order to get the filtered set of objects.

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

Sidebar

Related Questions

I'm a bit stuck on the following linq query. I'm trying to find all
I seem to be a bit stuck on this, but my experience in Linq
I am a bit stuck here and can't think further. public struct CandidateDetail {
I'm a bit stuck with try to generate a complex if statement like the
I'm a bit stuck trying to get my code to output correctly, see below.
I'm a bit stuck repairing a faulty table (on Hbase 0.92.1-cdh4.0.0, Hadoop 2.0.0-cdh4.0.0) There
I am a bit stuck on one problem for a few hours now. Let`s
I'm a bit stuck with my code: def setVenueImage(img): img = images.Image(img.read()) x, y
I've come a bit stuck this afternoon with a bug in my web application
I'm a bit stuck on this - I am using a Wordpress shortcode with

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.