Hi,
In my BL (will be a public API), I am using ICollection as the return types in my Find methods, like:
public static ICollection<Customer> FindCustomers()
{
Collection<Customer> customers = DAL.GetCustomers();
return customers;
}
Note the use of ICollection instead of Collection<>.
Now in my GUI, I need to cast the results back to Collection, like:
Collection<Customer> customers = (Collection<Customer>)BL.FindCustomers();
This is because I need to use some Collection<> specific methods on my returned list, which I cannot do with ICollection<>.
Is this the correct usage? Or should I simply change the return type from Collection<> instead to ICollection<> in order to avoid this casting?
Secondly, I did not use IEnumerable because it is more generic than ICollection and does not even have simple properties like Count. And I really don’t see a point in generalizing the return types here. Am I missing something important?