Mega Code Archive

 
Categories / VB.Net / LINQ
 

Using Take While to get elements starting from the beginning until a condition

Imports System.IO Imports System.Reflection Imports System.Linq Imports System.Xml.Linq Public Class MainClass    Public Shared Sub Main         Dim numbers() As Integer = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}         Dim firstNumbersLessThan6 = From num In numbers Take While num < 6         'Dim firstNumbersLessThan6 = numbers.TakeWhile(Function(n) n < 6)         Console.WriteLine("First numbers less than 6:")         For Each n In firstNumbersLessThan6             Console.WriteLine(n)         Next    End Sub End Class