What is LINQ in C#
LINQ stands for Language Integrated Query. LINQ enables us to query various type of data sources such as SQL server, XML documents, in memory objects like arrays and generics. In general, if you want to fetch a data from a data source, then you must need to have some technical info about the underlying technology of that specific data source. For example, if you want to fetch data from SQL, then you must need to have some knowledge about SQL query syntax and technology behind its usage. Same thing goes for XML documents, in memory objects and others.
LINQ enables us to work with various type of data sources in a similar coding style without worrying about their actual query syntax or underlying technologies. LINQ also has compile time error checking feature which eliminates the possibility of any kind of runtime errors.
In LINQ, we have different type of LINQ providers like LINQ to SQL, LINQ to XML, LINQ to objects etc. All of these data providers basically convert your LINQ query into a syntax which a data source specific to them can understand. For example, LINQ to SQL provider will convert your LINQ query into SQL query syntax and fetch the data. It all happens behind the scenes so you don’t need to worry about it.
IEnumerable<T> interface is part of System.Collections.Generic namespace. So, any type which implements IEnumerable<T> interface will have access to all the extension methods which are present in Enumerable class of System.Linq namespace. If you are making use of generics and LINQ, then you must add these 2 namespaces on the top of your code file. Enumerable class is static and noninheritable because it is of sealed type.
In LINQ extension methods works with delegate-based query syntax. As we know, delegates are nothing more than a pointer to a function. To pass a delegate as parameter, we make use of Lambda Expressions which makes our code more readable and maintainable.