List of subclasses <T> does not preserve list functions

I subclassed the general list so that I can implement the new interface

public class CustomersCollection : List<Customer>, IEnumerable<SqlDataRecord>
{
...
}

When I change the field definition to a new class (see the example of old and new lines below), I get all kinds of compilation errors for 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 the ClientCollection not inherit the IQueryable, IEnumerable interface implementations for the list?

Official mistake:

'CustomersCollection' does not contain a definition of “where” and there is no extension method “Where” accepting the first argument of the type “CustomersCollection” can be found (do you miss the using directive or the assembly reference?)


, IEnumerable , IEnumerable . ?

+5
1

, List<T>. , using System.Linq; ? , System.Core.dll.

Edit

List<U> IEnumerable<T>, / , . :

CustomerCollection customers = new CustomerCollection();
customers.Add(new Customer() { Name = "Adam" });
customers.Add(new Customer() { Name = "Bonita" });
foreach (Customer c in customers.Where<Customer>(c => c.Name == "Adam"))
{
    Console.WriteLine(c.Name);
}

...

class Customer { public string Name { get; set; } }    

class Foo { }

class CustomerCollection : List<Customer>, IEnumerable<Foo>
{
    private IList<Foo> foos = new List<Foo>();

    public new IEnumerator<Foo> GetEnumerator()
    {
        return foos.GetEnumerator();
    }
}
+11

All Articles