Solved

Urgent: Correcting a basic syntax error

Posted on 2004-11-01
214 Views
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'
0
Question by:mte01
    3 Comments
     
    LVL 48

    Accepted Solution

    by:
    Try to use casting, something like this:

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

    Expert Comment

    by:AlexFM
    I tested this, it's OK.
    0
     
    LVL 3

    Author Comment

    by:mte01
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now