What is the exact use of AsEnumerable? Will it change non-enumerable collection to enumerable collection?.Please give me a simple example.
From the "Remarks" section of the MSDN documentation:
The
AsEnumerablemethod has no effect other than to change the compile-time type of source from a type that implementsIEnumerabletoIEnumerableitself.
AsEnumerablecan be used to choose between query implementations when a sequence implementsIEnumerablebut also has a different set of public query methods available. For example, given a generic classTablethat implementsIEnumerableand has its own methods such asWhere,Select, andSelectMany, a call toWherewould invoke the publicWheremethod ofTable. ATabletype that represents a database table could have aWheremethod that takes the predicate argument as an expression tree and converts the tree to SQL for remote execution. If remote execution is not desired, for example because the predicate invokes a local method, theAsEnumerablemethod can be used to hide the custom methods and instead make the standard query operators available.