Solved

What is the easiest way to find the number of occurances of a particular item in an arraylist?

Posted on 2013-06-14
2
195 Views
Last Modified: 2013-06-17
The title says it all.
0
Comment
Question by:NevSoFly
2 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
ID: 39249495
Two ways to do this. First would be using LINQ. There's a discussion about that at http://www.vbforums.com/showthread.php?674781-Counting-number-of-occurrences-of-element-within-array-or-arraylist

The other way is the manual way is below

Private Function NumberOfInstances(ByVal SearchFor As String, ByVal SearchList As ArrayList) As Integer
        Dim Counter As Integer = 0
        Dim i As Integer
        For i = 0 To SearchList.Count - 1
            If CStr(SearchList(i)) = SearchFor Then
                Counter += 1
            End If
        Next

        Return Counter
    End Function

Open in new window

0
 

Author Closing Comment

by:NevSoFly
ID: 39253045
perfect.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now