LINQ is the new way of querying data from various sources. Langugae integrated query supports
- · LINQ to Objects
- · LINQ to DataSets
- · LINQ to SQL
- · LINQ to Entities
- · LINQ to XML
LINQ to Objects
LINQ to object supports the native query language in .Net with intellisense. Query Operators like select, where, join, etc. can be used against any .NET collection. LINQ integrate the use of Lambda expressions. It also uses the deferred query execution feature, where the query will be executed at the time of referring the result.
LINQ to Object example
namespace ConsoleApplication{ class Program { static void Main(string[] args) { string[] names = { "John", "George", "Anitha", "Hari", "Vishnu", "Gauri" }; Func<string, bool> filter = s => s.Length == 5; Func<string, string> extract = s => s; Func<string, string> project = s => s.ToUpper(); IEnumerable<string> expr = names .Where(filter) .OrderBy(extract) .Select(project); foreach (string item in expr) Console.WriteLine(item); Console.Read(); } } }
Result:
GAURI