473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Looping around an arraylist in c#

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.
Nov 17 '05 #1
2 22132
HI,

try this:

1)
string result = string.Empty;
foreach(string val in alSearchCriteria)
{
if(val != null && val != string.Empty)
result += val + "\r\n";
}

myLabel.Text = result;
2)
string result = string.Empty;
for( int i=0; i<alSearchCriteria.Count; i++)
{
string val = alSearchCriteria[i] as string;
if(val != null && val != string.Empty)
result += val + "\r\n";
}

myLabel.Text = result;
But I don't understand why you put the null-values into the ArrayList,
but well...

Hope this helps,

Martin
Stephen 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.

Nov 17 '05 #2
Hi,

A simple foreach will solve your problem, as long as all the elements are
of the same type (seems to be your case) you will be ok

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:6A**********************************@microsof t.com...
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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jase | last post by:
I have put together the Google Web API with PHP, as described in O'Reilly's Google Hacks (Hack#55). However, the API only allows you to return 10 results. Hack #51 shows how to Loop around the...
2
by: Stephen | last post by:
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...
4
by: Hans De Schrijver | last post by:
I have a private ArrayList variable that holds objects of various types, though they're all derived from a common base class (User). What I would like to do is provide public accessor properties...
9
by: vbportal | last post by:
Hi, I would like to add BitArrays to an ArrayList and then remove any duplicates - can someone please help me forward. I seem to have (at leaset ;-) )2 problems/lack of understanding (see test...
4
by: Peter | last post by:
I run into this situation all the time and I'm wondering what is the most efficient way to handle this issue: I'll be pulling data out of a data source and want to load the data into an array so...
2
by: AppleBag | last post by:
Hello everybody, I am beginning the .NET learning curve, and I have learned how to load a listbox with a directory list of files using this code: If FolderBrowserDialog1.ShowDialog() =...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
4
by: tshad | last post by:
I have an ArrayList of thread pointers that I want delete from my list when the Thread in not alive and status is stopped. But I want to do it from the foreach loop I am looping through. ...
1
by: cmdolcet69 | last post by:
How can i get (gage) to represent gages 3 and 4 in my array list..... I have a total of 6 points. 4 points are on COM1 and 2 points are on COM2 Points 3 and 4 (which are on COM2) should...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.