I have the following class:
public class Customer
{
public int location { get; set; }
public List<int> slots { get; set; }
}
Then I have a list of customers:
List<Customer> lstCustomer = new List<Customer>();
Then I have a slot number:
int slot = 4;
I would like to return an integer of a specific location that the slot belongs to. (See customer class above)
This is what I have so far:
int? location = lstCustomer
.Where(l => l.slots.Any(x => slot))
.FirstOrDefault();
But this does not work (Error: Cannot convert int to bool). Any help would be appreciated. Thank you.
int? location = lstCustomer.FirstOrDefault(x => x.slots.Contains(slot))?.location;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With