Using Take to get the first 3 orders from employeeList : List « Data Structure « VB.Net

4.Data Structure
5.Data Types
7.Date Time
10.File Directory
13.Internationalization I18N
14.Language Basics
16.Network Remote
20.Windows Presentation Foundation
21.Windows System
VB.Net » Data Structure » ListScreenshots 
Using Take to get the first 3 orders from employeeList

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 employeeList As List(Of Employee= New List(Of Employee)

        employeeList.Add(New Employee With {.EmployeeID = 1, .CompanyName = "Company A", .Address = "Street 1", .City = "City 1", .Region = "North"})
        employeeList.Add(New Employee With {.EmployeeID = 2, .CompanyName = "Company B", .Address = "Street 2", .City = "City 2", .Region = "South"})
        employeeList.Add(New Employee With {.EmployeeID = 3, .CompanyName = "Company C", .Address = "Street 3", .City = "City 3", .Region = "West"})
        employeeList.Add(New Employee With {.EmployeeID = 4, .CompanyName = "Company D", .Address = "Street 4", .City = "City 4", .Region = "East"})
        employeeList.Add(New Employee With {.EmployeeID = 5, .CompanyName = "Company E", .Address = "Street 5", .City = "City 5", .Region = "North"})
        employeeList.Add(New Employee With {.EmployeeID = 6, .CompanyName = "Company F", .Address = "Street 6", .City = "City 6", .Region = "South"})

        Dim first3WAPayments = From cust In employeeList, ord In cust.Payments _
                             Where cust.Region = "WA" _
                             Select cust.EmployeeID, ord.PaymentID, ord.PaymentDate _
                             Take 3

        For Each emp In first3WAPayments

    End Sub

End Class

Related examples in the same category
1.List Range operation
2.Check the List.Capacity before and after adding elements
3.Does List contain a certain element
4.Add element to List at position of 2
5.Remove an element from List
6.Trim down extra capacity from List
7.Clear a List
8.Using a BindingSource component to bind a list to a DataGridView control
9.Uses a cursor to step through the message queues and list the public queues on the network.
10.Using Order By to sort a list of words alphabetically
11.Using Order By to sort a list of words by length
12.Using Group By to partition a list of words by first letter
13.Converting ToList
14.Using a Where clause to find all projectList that are in stock and cost more than 3.00 per unit
15.Using Payment By to sort a list of projectList by units in stock from highest to lowest
16.Using Except to do minus between two lists
17.Use Action<(Of <(T>)>) delegate to print the contents of a List<(Of <(T>)>) object.
18.List the Unicode code point of each of the control characters.
19.Create a SortedList using the default comparer.
20.Create a SortedList using the specified case-insensitive comparer.
21.Create a SortedList using the specified CaseInsensitiveComparer,
22.Create a SortedList using the StringComparer.InvariantCultureIgnoreCase value.
23.Implements a TextWriterTraceListener named myWriter to write to the console screen.
24.All three overloads of the CopyTo method in List<(Of <(T>)>)
25.Create a fixed-size wrapper around an ArrayList.
26.Synchronize an ArrayList, determine if an ArrayList is synchronized and use a synchronized ArrayList.
27.LinkedListNode<(Of <(T>)>), adds it to a LinkedList<(Of <(T>)>), tracks values of its properties as the LinkedList<(Of <(T>)>) changes.
28.What is the different between the Count and Capacity
29.Get the fourth element
30.List(T) Class is a strongly typed list of objects that can be accessed by index
31.Add strings to List of String and use For Each loop to show each item
32.Insert in the middle of a List
33.Remove an element from List
34.Trim a List
35.Clear a List
36.Convert element in List to string
37.List Linq operator: Any
38.List Linq operator: First
39.List Linq operator: Where
40.Create List(Of T) class that contains elements copied from the specified collection
41.Add another list to the current list
42.Get range from a List
43.Create List(Of T) class that is empty and has the specified initial capacity.
44.List(T).BinarySearch Method searches sorted List(Of T) using the default comparer
45.List(T).ConvertAll(TOutput) Method converts List(Of T) to another type
46.List(T).CopyTo Method copies a range of elements from the List(Of T) to one-dimensional array
47.List(T).ForEach Method Performs the specified action on each element of the List(Of T).
48.List(T).IndexOf Method searches for object and returns the zero-based index
49.List(T).LastIndexOf Method searches for the specified object and returns the zero-based index of the last occurrence
50.List(T).Reverse Method reverses the order of the elements in the specified range.
51.Add after a LinkedListNode
52.Create LinkedList(Of T) class that is empty.
53.LinkedListNode(T) Class represents a node in a LinkedList(Of T).
54.Copies the ListDictionary to an array with DictionaryEntry elements
55.ListDictionary.Add Method adds an entry with the specified key and value into the ListDictionary.
56.ListDictionary.Contains Method tells whether the ListDictionary contains a specific key.
57.ListDictionary.CopyTo Method copies the ListDictionary entries to a one-dimensional Array
58.LinkedListNode(T) Class represents a node in a LinkedList(Of T). This class cannot be inherited.
59.Check the Capacity and Count
60.Check the existance of an item with Contains method
61.Get the item by index
62.Remove a range
63.Insert range  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.