Best way to remove empty elements from ArrayList?

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
Tom SageAsked:
Who is Participating?
 
Jens FiedererTest Developer/ValidatorCommented:
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
 
Jens FiedererTest Developer/ValidatorCommented:
Pure VB.NET syntax using a loop, or is LINQ OK?
0
 
Tom SageAuthor Commented:
Sure, LINQ is ok.


Thanks
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Tom SageAuthor Commented:
Can you give me an example using the List<objectType> ?

Thank you very much.

0
 
Jens FiedererTest Developer/ValidatorCommented:
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
 
Tom SageAuthor Commented:
jensfiederer - Thanks for the quick response, and the excellent code !!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.