T
t f
Hi
I have some code which does basically the following:
void A()
{
ArrayList al1 = new ArrayList();
al1.AddRange(GetSomeNames());
//do something with al1...
}
ArrayList GetSomeNames()
{
ArrayList al2 = new ArrayList();
foreach (string s in some array)
{
if (s != string.empty)
al2.Add(s);
}
return al2;
}
Now my problem is -> if GetSomeNames() returns an empty ArrayList then
al1.AddRange throws an exception saying it cannot add null which is fine. To
get around this I simply use a try { } catch { } but is there a cleaner ways
of doing it (i.e. not having to use the try catch)?
I could create a new arraylist with the returned value and then check its
count before doing an addrange on it but this seems to be a crazy way...
any thoughts or suggestions?
thanks
tf
I have some code which does basically the following:
void A()
{
ArrayList al1 = new ArrayList();
al1.AddRange(GetSomeNames());
//do something with al1...
}
ArrayList GetSomeNames()
{
ArrayList al2 = new ArrayList();
foreach (string s in some array)
{
if (s != string.empty)
al2.Add(s);
}
return al2;
}
Now my problem is -> if GetSomeNames() returns an empty ArrayList then
al1.AddRange throws an exception saying it cannot add null which is fine. To
get around this I simply use a try { } catch { } but is there a cleaner ways
of doing it (i.e. not having to use the try catch)?
I could create a new arraylist with the returned value and then check its
count before doing an addrange on it but this seems to be a crazy way...
any thoughts or suggestions?
thanks
tf