Reputation: 308
Hi I have a list of objects i want to return the updated object if condition matches else the object. below is the code i tried. IT does not work. It simply returns me the matches found with update. I want those values also which do not match key value from list without updation. Can we do this?
var bindingData = dataSource.Where(x => filesFoundDictionary.Any(y => y.Key == x.FileName)).Select(x => { x.Select = true; return x; }).ToList();
Upvotes: 0
Views: 370
Reputation: 125650
You shouldn't use Where
and put your condition within Select
statement instead:
var bindingData = dataSource
.Select(x =>
{
if(filesFoundDictionary.ContainsKey(s.FileName))
x.Select = true;
return x;
}).ToList();
Upvotes: 2