• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

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].ToString(),"\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'
0
mte01
Asked:
mte01
  • 2
1 Solution
 
AlexFMCommented:
Try to use casting, something like this:

((String[])data[i])[j] = tk.NextToken();
0
 
AlexFMCommented:
I tested this, it's OK.
0
 
mte01Author Commented:
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!!!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now