I stumbled across this very strange compiler behavior. I am trying to remove items from ObservableCollection based on some condition. Here is what I have in my code which throws error
public ObservableCollection<StandardContact> StandardContacts { get; set; }
....
StandardContacts.Remove(s => s.IsMarked); //Compiler Error
The error is as follows
Error Cannot convert lambda expression to type 'RelayAnalysis_Domain.Entity.StandardContact' because it is not a delegate type
Surprisingly, the code below in the same method works
var deleteCount = StandardContacts.Where(s => s.IsMarked).Count(); //This Works
I already have following imports in my class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Entity;
This question may turnout to be silly, but it has had my head scratching.
Note: Even the Intellisence shows the same error
As the error message unclearly states, you can’t do that.
ObservableCollection<T>does not have a method that removes items that match a condition. (unlikeList<T>, which hasRemoveAll())Instead, you can loop backwards through the collection and call
Remove().