Aracılığıyla paylaş


Toplama İşlemleri

Toplama işlemi değerleri topluluğu'ndan tek bir değer hesaplar.Toplama işlemi örneği gelen bir ayın tutulacak günlük sıcaklık değerlerinin ortalama günlük sıcaklık hesaplıyor.

Bir sıra numarası iki farklı toplama işlemleri sonuçları aşağıda gösterilmiştir.İlk işlem sayıları toplar.İkinci işlem, sırayla en büyük değeri verir.

LINQ Toplama işlemleri

Toplama işlemleri standart sorgu işleci yöntemleri aşağıdaki bölümünde listelenir.

Yöntemler

Yöntem adı

Description

C# sorgu ifade sözdizimi

Visual BasicSorgu ifade sözdizimi

Daha Fazla Bilgi

Toplama

Değerler topluluğunun bir özel toplama işlemi gerçekleştirir.

Yoktur.

Yoktur.

Enumerable.Aggregate``1

Queryable.Aggregate``1

Ortalama

Değerler topluluğu ortalama değerini hesaplar.

Yoktur.

Aggregate … In … Into Average()

Enumerable.Average

Queryable.Average

Sayı

Bir koleksiyondaki öğeler, doðrulama bir işlev karşılayan isteğe bağlı olarak yalnızca bu öğelerin sayar.

Yoktur.

Aggregate … In … Into Count()

Enumerable.Count``1

Queryable.Count``1

LongCount

Bir koleksiyondaki öğeler büyük, doðrulama bir işlev karşılayan isteğe bağlı olarak yalnızca bu öğelerin sayar.

Yoktur.

Aggregate … In … Into LongCount()

Enumerable.LongCount``1

Queryable.LongCount``1

En Fazla

Bir koleksiyondaki en yüksek değeri belirler.

Yoktur.

Aggregate … In … Into Max()

Enumerable.Max

Queryable.Max``1

En Küçük

Bir koleksiyondaki en düşük değeri belirler.

Yoktur.

Aggregate … In … Into Min()

Enumerable.Min

Queryable.Min``1

Sum

Bir koleksiyondaki değerlerin toplamını hesaplar.

Yoktur.

Aggregate … In … Into Sum()

Enumerable.Sum

Queryable.Sum

Sorgu ifade sözdizimi örnekleri

Ortalama

Aşağıdaki kod örneği Aggregate Into Average yan tümcesinde Visual Basic ortalama sıcaklık sıcaklıklar temsil eden sayı dizisi hesaplamak için.

Dim temperatures() As Double = {72.0, 81.5, 69.3, 88.6, 80.0, 68.5}

        Dim avg = Aggregate temp In temperatures Into Average()

        ' Display the result.
        MsgBox(avg)

        ' This code produces the following output: 

        ' 76.65

Sayı

Aşağıdaki kod örneği Aggregate Into Count yan tümcesinde Visual Basic 80 ya da daha büyük olan bir dizi değerleri saymak için.

Dim temperatures() As Double = {72.0, 81.5, 69.3, 88.6, 80.0, 68.5}

        Dim highTemps As Integer = Aggregate temp In temperatures Into Count(temp >= 80)

        ' Display the result.
        MsgBox(highTemps)

        ' This code produces the following output: 

        ' 3

LongCount

Aşağıdaki kod örneği Aggregate Into LongCount yan tümcesinde Visual Basic bir dizideki değerleri saymak için.

Dim temperatures() As Double = {72.0, 81.5, 69.3, 88.6, 80.0, 68.5}

        Dim numTemps As Long = Aggregate temp In temperatures Into LongCount()

        ' Display the result.
        MsgBox(numTemps)

        ' This code produces the following output: 

        ' 6

En Fazla

Aşağıdaki kod örneği Aggregate Into Max yan tümcesinde Visual Basic sıcaklıklar temsil eden sayı dizisi içinde en yüksek Sıcaklığı hesaplamak için.

Dim temperatures() As Double = {72.0, 81.5, 69.3, 88.6, 80.0, 68.5}

        Dim maxTemp = Aggregate temp In temperatures Into Max()

        ' Display the result.
        MsgBox(maxTemp)

        ' This code produces the following output: 

        ' 88.6

En Küçük

Aşağıdaki kod örneği Aggregate Into Min yan tümcesinde Visual Basic sıcaklıklar temsil eden sayı dizisi minimum sıcaklık hesaplamak için.

Dim temperatures() As Double = {72.0, 81.5, 69.3, 88.6, 80.0, 68.5}

        Dim minTemp = Aggregate temp In temperatures Into Min()

        ' Display the result.
        MsgBox(minTemp)

        ' This code produces the following output: 

        ' 68.5

Sum

Aşağıdaki kod örneği Aggregate Into Sum yan tümcesinde Visual Basic bir dizi harcamaları temsil eden değerlerin toplam Harcama tutarı hesaplamak için.

Dim expenses() As Double = {560.0, 300.0, 1080.5, 29.95, 64.75, 200.0}

        Dim totalExpense = Aggregate expense In expenses Into Sum()

        ' Display the result.
        MsgBox(totalExpense)

        ' This code produces the following output: 

        ' 2235.2

Ayrıca bkz.

Görevler

Nasıl yapılır: Bir CSV Metinde Dosyasında Sütun Değerlerini Hesaplama (LINQ)

Nasıl yapılır: LINQ Kullanarak Count, Sum veya Average Verisi (Visual Basic)

Nasıl yapılır: LINQ Kullanarak Bir Sorgu Sonucunda En Düşük ve En Fazla Değeri Bulma (Visual Basic)

Nasıl yapılır: Bir Dizin Ağacındaki En Büyük Dosya veya Dosyalar için Sorgu (LINQ)

Nasıl yapılır: Bir Klasör Kümesindeki Toplam Bayt Sayısını Sorgulama (LINQ)

Başvuru

Aggregate Tümcesi (Visual Basic)

System.Linq

Kavramlar

Standart Sorgu İşleçlerine Genel Bakış