How effective is the ToList () method? Will he create a new list and how much memory will it do, assuming these are POCOs? Does this change if it is a value type and not a POCO?
The ToList() method implements this collection by creating a new list and filling it with elements of this collection. Linq.ToList() implementation :
public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source) { if (source == null) throw Error.ArgumentNull("source"); return new List<TSource>(source); }
By doing so, you do not gain the strength of a defensive execution if necessary
Will the size of the list determine the effectiveness or the size of the list does not determine the value of ToList ()?
As he calls the List copy constructor, and he creates a new list, then he will work on each of the elements. Therefore, it will work in O(n) - this means that the size of the list matters. MSDN documentation about copy constructor work:
Initializes a new instance of the List class, which contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
As mentioned in the comments by @Jason's comment, Copy Constructor is smart and efficient, but does it when it is not needed, another O(n) operation that should not happen
If the list is passed in IEnumerable and then ToList () is called on it, will it just return the original object?
No. It will create a new list as shown above.
As for your sample code:
input = input.OrderBy(s => s.Thing).ToList(); foreach(var thing in input) {
As you get a materialized list (and not IQueriable / IEnumerable , which can be run in differentiated execution), adding ToList after adding does not do you any good.
You can look here, it can also help: When to use LINQ.ToList () or .ToArray ()