471,357 Members | 1,237 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,357 software developers and data experts.

Looping around items in an Arraylist

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.
Jul 21 '05 #1
2 2368
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
Jul 21 '05 #2
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
}
On Wed, 11 May 2005 12:26:03 +0200, Stephen <St*****@discussions.microsoft.com> wrote:
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.


--
Happy coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by CanoeGuy | last post: by
2 posts views Thread by Stephen | last post: by
3 posts views Thread by VB Programmer | last post: by
2 posts views Thread by Stephen | last post: by
3 posts views Thread by Stuart | last post: by
10 posts views Thread by pamelafluente | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.