Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to use Array.FindAll<T> method to get all array elements that match a condition in VB.NET

1 Answer

0 votes
Module Module1

    Sub Main()
        Dim arr() As Integer = CreateArray(25, 0, 100)
        Dim lBound As Integer = 20
        Dim uBound As Integer = 70

        Dim foundItems() As Integer = Array.FindAll(arr, Function(x) x >= lBound And x <= uBound)

        For i As Integer = 0 To foundItems.Length - 1
            Console.Write("{0}  ", foundItems(i))
        Next
    End Sub

    Private Function CreateArray(total_elements As Integer,
                                 lower As Integer, upper As Integer) As Integer()
        Dim rnd As New Random()
        Dim list As New List(Of Integer)
        For i As Integer = 1 To total_elements
            list.Add(rnd.Next(lower, upper + 1))
        Next
        Return list.ToArray()
    End Function

End Module


' run:
' 
' 33  51  64  28  64  65  55  56  28  54

 



answered Apr 16, 2016 by avibootz
...