Trouble accessing ArrayList with index

Posted on 2006-06-02
Medium Priority
Last Modified: 2010-04-16
I have an ArrayList populated from a DataReader:

object[] values = new object[dr.FieldCount];

then I try to access it like this:


however I can't even get the thing to compile.  I get this error:
"Cannot apply indexing with [] to an expression of type 'object'"

I have tried casting it every way I could think of without success.  If comment out the part where I try to access it, and then run the program, and then put it in break mode right next to where I am trying to access it, I am able to get what I need in the command window using the exact same line: EndSegData[x][y].  So, it works in the command window but not in the program.

I could use some help getting it to work in my program.

Thank you.
Question by:ng_king
LVL 48

Accepted Solution

AlexFM earned 1000 total points
ID: 16819685
Try this:

LVL 96

Expert Comment

by:Bob Learned
ID: 16819722
Here is a little test that I came up with:

      ArrayList test = new ArrayList();

      for (int i = 0; i < 10; i++)
        object[] values = new object[]{"1", 5, 10.1, "Bob", 'C'};

      int n = Convert.ToInt32(((object[])test[0])[1].ToString());


Author Comment

ID: 16819769
I didn't try it with the right paren around the first element-- I guess that's the trick.  Thank you very much.  

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

807 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