To use LINQ in your program you need a LINQ expression. Then then return type of LINQ expression is an iterator object that implements IEnumerable<T> and enumerating over the iterator object, LINQ performs its work. However this makes some questions about  LINQ

  • How LINQ works?
  • How LINQ execute statements?
  • How LINQ filter results?

LINQ works differently for different type of data type for example if you are using LINQ with database then it open database connections, perform SQL commands and return requested results back to you. In case of LINQ to objects LINQ simply perform uses for each loop to scan through the collection and return result back to you.

LINQ to objects is always slower as compare to comparable for each block, because this overhead is due to additional methods and delegate works. If you want to implement a advance search routine for in memory objects then un this case using LINQ will be a good idea as compare to for each block.

There are some point to remember while using LINQ to objects

  1. LINQ expressions work on objects that implement Enumerable<T> and LINQ
    expressions return objects that implement IEnumerable<T>.