mte01
asked on
Urgent: Correcting a basic syntax error
Can anyone find why the following error is occuring in the following piece of C# code:
private ArrayList tot = new ArrayList(20);
private ArrayList data = new ArrayList(20);
private void tokenizeline(String line,int i)
{
tot[i] = line;
StringTokenizer tk = new StringTokenizer(tot[i].ToS tring(),"\ t");
data[i] = new String[tk.CountTokens()];
for(int j=0;tk.HasMoreTokens();j++ )
{
data[i][j] = tk.NextToken();
}
}
Error at data[i][j]: Cannot apply indexing with [] to an expression of type 'object'
private ArrayList tot = new ArrayList(20);
private ArrayList data = new ArrayList(20);
private void tokenizeline(String line,int i)
{
tot[i] = line;
StringTokenizer tk = new StringTokenizer(tot[i].ToS
data[i] = new String[tk.CountTokens()];
for(int j=0;tk.HasMoreTokens();j++
{
data[i][j] = tk.NextToken();
}
}
Error at data[i][j]: Cannot apply indexing with [] to an expression of type 'object'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I tested this, it's OK.
ASKER
Yess...it works.......and what I did is somethin a little bit longer:
String[] temp = new String[tk.CountTokens()];
for(int j=0;tk.HasMoreTokens();j++ )
{
temp[j] = tk.NextToken();
}
data[i] = temp;
Yours is better....Thanks!!!
String[] temp = new String[tk.CountTokens()];
for(int j=0;tk.HasMoreTokens();j++
{
temp[j] = tk.NextToken();
}
data[i] = temp;
Yours is better....Thanks!!!