Filtering (Where): Using a Where clause to find all projects that are out of stock. : Where « LINQ « VB.Net






Filtering (Where): Using a Where clause to find all projects that are out of stock.

  


Imports System.IO
Imports System.Reflection
Imports System.Linq
Imports System.Xml.Linq
Imports System.Collections
Imports System.Collections.Generic
Public Class Project
    Public ProjectID As Integer
    Public ProjectName As String
    Public Category As String
    Public Cost As Decimal
    Public YearLength As Integer
End Class

Public Class Employee
    Public EmployeeID As String
    Public CompanyName As String
    Public Address As String
    Public City As String
    Public Region As String
    Public PostalCode As String
    Public Country As String
    Public Phone As String
    Public Fax As String
    Public Payments As Payment()
End Class

Public Class Payment
    Public PaymentID As Integer
    Public PaymentDate As DateTime
    Public Total As Decimal
End Class



Public Class MainClass
    Public Shared Sub Main()
        Dim projectList As List(Of Project) = New List(Of Project)
        projectList.Add(New Project With {.ProjectID = 1, .ProjectName = "A", .Category = "Design", .Cost = 18D, .YearLength = 39})
        projectList.Add(New Project With {.ProjectID = 2, .ProjectName = "B", .Category = "Testing", .Cost = 19D, .YearLength = 17})
        projectList.Add(New Project With {.ProjectID = 3, .ProjectName = "C", .Category = "Coding", .Cost = 10D, .YearLength = 13})
        projectList.Add(New Project With {.ProjectID = 4, .ProjectName = "D", .Category = "Meeting", .Cost = 22D, .YearLength = 53})
        projectList.Add(New Project With {.ProjectID = 5, .ProjectName = "E", .Category = "Writing", .Cost = 21.35D, .YearLength = 0})
        projectList.Add(New Project With {.ProjectID = 6, .ProjectName = "F", .Category = "Testing", .Cost = 25D, .YearLength = 120})
        projectList.Add(New Project With {.ProjectID = 7, .ProjectName = "G", .Category = "Coding", .Cost = 30D, .YearLength = 15})
        projectList.Add(New Project With {.ProjectID = 8, .ProjectName = "H", .Category = "Design", .Cost = 40D, .YearLength = 6})
        projectList.Add(New Project With {.ProjectID = 9, .ProjectName = "I", .Category = "Coding", .Cost = 97D, .YearLength = 29})

        Dim soldOutProjects = From prod In projectList Where prod.YearLength = 0 Select prod
        For Each prod In soldOutProjects
            Console.WriteLine(prod.ProjectName & " is sold out!")
        Next

    End Sub


End Class

   
    
  








Related examples in the same category

1.Where with a function
2.Check String start-with value
3.Equals vs = in query
4.Query for String length
5.Where Drilldown
6.Find files created within the last year
7.Linq to query File System: shows all mapped network drives
8.Shows all public methods in an assembly, with duplicates removed
9.Shows all public methods in an assembly.
10.Filtering Numbers
11.Indexed Where
12.An indexed Where clause that returns digits whose name is shorter than their value