Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 132,690 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,311 people online right now. Registration is fast and FREE... Join Now!




Quick ArrayList Question

 
Reply to this topicStart new topic

Quick ArrayList Question

cbr4rusty
post 1 Jun, 2008 - 05:53 PM
Post #1


New D.I.C Head

*
Joined: 15 Apr, 2008
Posts: 25

How can I determine whether an index of myList has a value or not?
I doesn't seem to work if I test it to null (or try to convert it to a string and test it to null).

CODE

                        if (Count == 4)
                        {
                            if (myList[4] == null)
                            {
                                myList.Remove(myList[4]);
                            }
                        }

User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 1 Jun, 2008 - 07:15 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,062



Thanked 177 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Well this will be dependent on how you are storing the value. For instance if I purposely store a null value, I can test for that null value just fine.

csharp

private void button1_Click(object sender, EventArgs e)
{
ArrayList a = new ArrayList();

a.Add(1);
a.Add(null);
a.Add(3);
a.Add(5);

if (a[1] == null) { MessageBox.Show("Is empty"); }

}


But if you are talking about an empty string being placed in, then you will have to compare it to an empty string. You could use String.IsNullOrEmpty() for that sort of comparison.

So hopefully one of those choices helps you out. It all depends on how you are storing values.

Hope that helps. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:38AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month