Do you have a default type that you prefer to use in your dealings with the results of LINQ queries?
By default LINQ will return an IEnumerable<>
or maybe an IOrderedEnumerable<>
. We have found that a List<>
is generally more useful to us, so have adopted a habit of ToList()
ing our queries most of the time, and certainly using List<>
in our function arguments and return values.
The only exception to this has been in LINQ to SQL where calling .ToList()
would enumerate the IEnumerable
prematurely.
We are also using WCF extensively, the default collection type of which is System.Array
. We always change this to System.Collections.Generic.List
in the Service Reference Settings dialog in VS2008 for consistency with the rest of our codebase.
What do you do?