VB.Net/LINQ/Count

Материал из VB Эксперт
Перейти к: навигация, поиск

Get count from the query

<source lang="vbnet">

Module Program

 Sub Main()
   Dim currentVideoGames() As String = {"A", "B", "this is a test", "D", "E", "S"}
   Dim numb As Integer = (From g In currentVideoGames _
               Where g.Length > 6 _
               Order By g _
               Select g).Count()
   Console.WriteLine("{0} items honor the LINQ query.", numb)
 End Sub

End Module


 </source>


Get the count of all employees hired this year.

<source lang="vbnet"> Imports System Imports System.Xml.Linq

   Public Class MainClass
       Public Shared Sub Main()
           Dim employees As XElement = XElement.Load("Employees.xml")
           Dim cnt = Aggregate ele In employees.<Employee> _
                     Where CDate(ele.<HireDate>.Value).Year = Now.Year _
                     Into Count()
           Console.WriteLine("{0} employees were hired this year.", cnt)
           
       End Sub
   End Class
  
   
 </source>