I have created a subclass of a generic list so that I could implement a new interface
public class CustomersCollection : List<Customer>, IEnumerable<SqlDataRecord>
{
...
}
When I change the field definition to the new class (see example of old and new lines below) I get all sorts of compile errors on things that should exist in the original list.
public CustomersCollection Customers { get; set; }
public void Sample()
{
Console.WriteLine(Customers.Where(x=>x.condition).First().ToString());
}
Why does CustomersCollection does not inherit the IQueryable, IEnumerable interface implementations for List?
The official error is:
‘CustomersCollection’ does not contain
a definition for ‘Where’ and no
extension method ‘Where’ accepting a
first argument of type
‘CustomersCollection’ could be found
(are you missing a using directive or
an assembly reference?)
It turns out that the custom implementation of IEnumerable causes all the extension methods that apply to IEnumerable to fail. Whats going on here?
The extension methods are available to a class that inherits from
List<T>. Perhaps you need to addusing System.Linq;to your code file? Also check that you have a reference toSystem.Core.dll.Edit
Since you have
List<U>andIEnumerable<T>being inherited/implemented by the same class, you need to provide the type when you use the extension methods. Example:… based on