We have a web project that contain its business methods in a class library project called “Bll.dll”
some methods of Bll.dll return List<> …
from a source – that i don’t remember now – told that returning Collection<> is better than returning List<>
Is it a valid ?
Note that i don’t make any process on values returned from BLL methods .. just view it in a web page
We have a web project that contain its business methods in a class library
Share
Collection<T>is implemented, IIRC, as a wrapper around anIList<T>, of which the default implementation isList<T>. Therefore aCollection<T>has at least one more abstraction than aList<T>, but in general this won’t be a bottleneck. In fact, you might consider returningIList<T>.Edit: here is the constructor of
Collection<T>, courtesy of reflector:so indeed, this wraps a layer of abstraction. The plus side of this is that you can add your own validation etc by subclassing
Collection<T>(which is not possible when usingList<T>directly or via subclassing, since there are no interestingvirtualmethods).The other thing to consider is that they will have the same overall performance in terms of “O” (assuming you use the default
List<T>implementation). Indexer lookup will beO(1), etc