Solved

Best way to remove empty elements from ArrayList?

Posted on 2010-09-07
6
716 Views
Last Modified: 2012-08-13
I would like to remove multiple empty elements from an ArrayList.

What is the best way to do this?  Would prefer VB.NET syntax. Using VS 20008.

Thanks
0
Comment
Question by:MisterT25
  • 3
  • 3
6 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
Comment Utility
Pure VB.NET syntax using a loop, or is LINQ OK?
0
 

Author Comment

by:MisterT25
Comment Utility
Sure, LINQ is ok.


Thanks
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
Comment Utility
Dim query = From student As Student In arrList _
                    Where student is not null _
                    Select student
dim list as new ArrayList(query.ToArray)


Of course, it's best nowadays not to use ArrayList at all.....List<objectType> is usually a better choice.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:MisterT25
Comment Utility
Can you give me an example using the List<objectType> ?

Thank you very much.

0
 
LVL 23

Expert Comment

by:Jens Fiederer
Comment Utility
After the same first line as above,

query.ToList()

gives you a List<Student>

(the original "arrList" doesn't really have to be an ArrayList, it can be any collection)
0
 

Author Closing Comment

by:MisterT25
Comment Utility
jensfiederer - Thanks for the quick response, and the excellent code !!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now