Just check the size before you try to access it using
GetUpperBound()
CStringArray arr;
arr.RemoveAll();
CString tst;
int i=1;
if( i<= arr.GetUpperBound())
tst = arr.ElementAt(i);
You can also use
GetSize()
, just remember that on an empty list that's going to give you zero where
GetUpperBound
will give you a -1 (size gives you the number of elements where UpperBound gives you the maximum index).