Reputation: 679
I want to compare the list with single item in C#. I am unable to write if(ListofHorses.Any(x=>x.horseId==model.HorseId))
. The ListofHorses
holds the count of horses like
[0] 123
[1] 124
[2] 125
which I want to compare with single model.horseId which is 120
.
var ListofHorses = horseDetails.HorseList().Where(x => x.AccId == user.AccountID && x.UserId == user.Id).Select(y=>y.HorseId).ToList();
Now, I want to compare those 3 values with single item. How to do this?
Upvotes: 0
Views: 308
Reputation: 12619
Your ListofHorses
object is collection of values
not object
. So you can directly check it as below:
ListofHorses.Contains(model.HorseId)
Upvotes: 1
Reputation: 1148
Use Contains to search for one value in a list.
var ListOfHorses = horseDetails.HorseList.Contains("HorseName").Where(blah, blah, blah);
Upvotes: 1