It seems quite similar, but my question is quite different. I have a list which consists of objects which are implementation of different interface. I want to delete a particular type's objects, but after passing another criteria. A sample code is given below.
// remove the not required parameters
foreach (EndPoint endPoint in endPoints)
{
var maps = endPoint.EndPointParameters
.Where(x => x is IEndPointParamMapCustom)
.Cast<IEndPointParamMapCustom>()
.Where(x => !x.IsActive)
.ToList();
foreach (var custom in maps)
{
endPoint.EndPointParameters.Remove(custom);
}
}
I want to remove the below foreach loop and remove the objects in the above single LINQ query. Is it possible? Thanks.
Qin LINQ stands for Query, you'll never perform this "single query" mutation without abusing the intent of LINQ.