loyalflow
loyalflow

Reputation: 14919

Is returning a ICollection when calling ToList efficient?

Say I am doing this in my EF repository:

public ICollection<User> GetUsers(...) 
{
   return this.UserRepository.Get(....).ToList();
}

When I call ToList, does that convert it to a List and then get 'downgraded' or recasted to ICollection?

Would it be better just to do:

public IList<User> GetUsers(...);  

Is this the same thing or one is more effecient that the other i.e. more casting involved or the like.

Upvotes: 1

Views: 61

Answers (1)

Selman Gen&#231;
Selman Gen&#231;

Reputation: 101701

I think there is no difference about efficiency.IList<T> inherit from ICollection<T>,You can return whichever you want.There is no significant difference.

Upvotes: 3

Related Questions