?
Solved

arraylist comparison

Posted on 2011-09-09
3
Medium Priority
?
312 Views
Last Modified: 2012-05-12
I had an arraylist with values

DOCX
DOC
DOCX
DOC
DOC
DOC

I want to check whether all the values in the arraylist are equal or not

here the arraylsit values are different (4 DOC 2 DOCX) if different i want to set a flag to false
else set flag to true.

0
Comment
Question by:shragi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36513756
It should be something along the lines of:
Dim baseLine As String = yourArrayList(0).ToString()
Dim allEqual As Boolean = True

For Each item In yourArrayList
    If item.ToString() <> baseLine Then
        allEqual = False
        Exit For
    End If
Next

If allEqual Then
    MessageBox.Show("All items are equal")
Else
    MessageBox.Show("All items are NOT equal")
End If

Open in new window

0
 
LVL 19

Accepted Solution

by:
Shahan Ayyub earned 2000 total points
ID: 36513961
Hi!

Have a look at this way:

            bool IsEqual=false;
            ArrayList elements = new ArrayList(new object[] { "DOC", "DOC", "DOC", "DOC", "DOC", "DOC" });
            elements.Sort();
            if (elements[elements.Count - 1] == elements[0])  
                IsEqual = true;

Open in new window

0
 
LVL 19

Assisted Solution

by:Shahan Ayyub
Shahan Ayyub earned 2000 total points
ID: 36514038
If you can use LINQ you should look at Distinct() and Count() methods. That would be even more shorter than my previous solution.

This link may help you on that: (where most of the LINQ examples are given)
http://msdn.microsoft.com/en-us/vbasic/bb688085

VB.Net version of my previous solution:
Dim IsEqual As Boolean = False
Dim elements As New ArrayList(New Object() {"DOC", "DOC", "DOC", "DOC", "DOC", "DOC"})
elements.Sort()
If elements(elements.Count - 1) = elements(0) Then
	IsEqual = True
End If

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

762 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