[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

arraylist comparison

Posted on 2011-09-09
3
Medium Priority
?
321 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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