Looping around items in an Arraylist

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an array list alSearchCriteria which contains values which vary each
time its created. It will always have 15 items in the arraylist each time its
created. Some of the values in the array list will be a string called null. I
want to create some way of looping through the arraylist and pulling back all
the values which aren't null and displaying them on some control like a
asp:label in .net.

Does anyone know how I could write such a loop in c# and is this the best
way of doing it.

So basically to summarise I need to write a loop which goes around my
arraylist and prints all the values which are not null to a label contol.
Could someone please help me with this.
 
Stephen,

This sounds so crazy an arraylist is for when something is dynamic. When you
use a fixed array use than a normal array. You even can place there than in
"Null" and you know that it is not affected.

What is the problem, because the only problem is how you fill your
textboxes. But that has as well to do how you named them or if you want to
make them dynamicly at runtime.

Cor
 
Stephen,

You can use a regular for loop or a foreach loop.
If all your items are strings use

foreach(string s in myArrayList)
{
if(s != "null")
// add to label
}

If you have some strings, and some other types retrieve objects

foreach(object o in myArrayList)
{
if(s is String && s == "null")
continue;

// add to label
}
 
Back
Top