Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Urgent: Correcting a basic syntax error

Posted on 2004-11-01
Medium Priority
Last Modified: 2010-04-15
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'
Question by:mte01
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 48

Accepted Solution

AlexFM earned 2000 total points
ID: 12461204
Try to use casting, something like this:

((String[])data[i])[j] = tk.NextToken();
LVL 48

Expert Comment

ID: 12461216
I tested this, it's OK.

Author Comment

ID: 12461220
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!!!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question