How to use LINQ in C#?



Language Integrated Query (LINQ) is a Microsoft .NET Framework component and the uniform query syntax in C#. It has a set of method names and extends the language with query expressions.

For LINQ in C#, use −

using System.Linq;

Let us see an example. Here we have used the LINQ computational methods Count and Average to find the count of elements and average of those elements in C# −

Example

 Live Demo

using System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 87, 92, 45, 65, 34, 88 };       Console.WriteLine(arr.Average());       Console.WriteLine(arr.Count());    } }

output

68.5 6
Updated on: 2020-06-20T17:11:39+05:30

598 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements