Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

การใช้ LINQ ใน C# (Language Integrated Query)

LINQ (Language Integrated Query) เป็น Component ของ .NET Framework และ Query Syntax มาตรฐานใน C# มี Method Names ชุดหนึ่ง และขยายภาษาด้วย Query Expressions

ใช้ LINQ ด้วย: using System.Linq;

ตัวอย่าง: Count และ Average

using System;
using System.Linq;

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

Output

68.5
6