"Extremest" <dn**********@charter.net> wrote:
Is there a way to add new items to an arraylist witht he indexer? like
with a normal array I can just do like array[x] = new. What I have
read with arraylist it will throw an exception if I try to do this.
Are you working with the ArrayList class? If so, the following code
works fine for me, with no exceptions thrown:
---8<---
using System;
using System.Collections;
class App
{
static void Main()
{
ArrayList list = new ArrayList();
list.Add(null);
list.Add(null);
list[0] = new App();
list[1] = new App();
}
}
--->8---
Are you doing something different?
Or
is there a way to find out how many things are actually in an array
without it counting the null sections? Say I have an array[10] but
only have 5 things in there how can I easily find out that there are 5?
It isn't clear whether you're talking about an array or an ArrayList. To
count the number of non-null items in *either* an array *or* an
ArrayList, then you need to iterate through the list and compare with
null - i.e. do the counting yourself:
---8<---
int count = 0;
foreach (object o in a)
if (a != null)
++count;
--->8---
-- Barry
--
http://barrkel.blogspot.com/