Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9021281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:13:11+00:00 2026-06-16T05:13:11+00:00

H ere is my code: An ArrayList of ArrayList that returns a float: public

  • 0

Here is my code: An ArrayList of ArrayList that returns a float:

public ArrayList walls=new ArrayList(); 

public void Start()
{
    walls[0] = ReturnInArrayList(279,275,0,0,90);
    walls[1] = ReturnInArrayList(62,275,0,0,0);
    walls[2] = ReturnInArrayList(62,275,62,0,90);
    walls[3] = ReturnInArrayList(217,275,62,-62,0);
    walls[4] = ReturnInArrayList(62,275,279,0,90);
    walls[5] = ReturnInArrayList(41,275,279,0,0);
    walls[6] = ReturnInArrayList(279,275,320,0,9);
    walls[7] = ReturnInArrayList(320,275,0,-279,0); 

    for (int i = 0; i < walls.Length; i++) {
        float a = (float)walls[i][0];
        float b = (float)walls[i][1];
        float c = (float)walls[i][2];
        float d = (float)walls[i][3];
        float e = (float)walls[i][4];
    }
}

ArrayList ReturnInArrayList(float a,float b,float c, float d, float e)
{
    ArrayList arrayList = new ArrayList();
    arrayList.Add(a);
    arrayList.Add(b);
    arrayList.Add(c);
    arrayList.Add(d);
    arrayList.Add(e);
    return arrayList;
}

It gives me the following error:

error CS0021: Cannot apply indexing with [] to an expression of type
`object’

I already did the casting, what is wrong? 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:13:12+00:00Added an answer on June 16, 2026 at 5:13 am

    The problem is that paredes[i] returns an object which is the return type of the ArrayList indexer. You need to cast this to an ArrayList to be able to access it:

    float a= (float)((ArrayList)paredes[i])[0];
    

    A better solution though is to use generics and populate a List<float> instead:

    List<float> RetornaEmList(float a,float b,float c, float d, float e)
    {
        return new List<float> { a, b, c, d, e };
    }
    

    then paredes is a List<List<float>> and your accessor can be changed to:

    float a = paredes[i][0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ere is my code (including css): <form id=contactform action=# method=post> <label for=name>Name</label> <input type=text
html that is being selected: some te<b>xt here is bold</b>ed, I guess |______________________| <-
I have several questions about best use of exceptions in Java. Consider the code
Within an ERE, a backslash character (\, \a, \b, \f, \n, \r, \t, \v)
Basically, I know that Label works for the basic string. But what I want
I have an xml file that contains this data: `<?xml version=1.0 encoding=UTF-8?> <WordList> <Words
<span class=here one-two-sdfs test>click1</span> <br /> <span class=here one-two-3er te3st>click2</span> <br /> <span class=here
error :: Cannot instantiate a class that does not have a no-argument constructor [ClassLibrary2.Class1].
I wrote custom VirtualFile and VirtualPathProvider implementations that are successfully obtaining embedded resources that
I've got some trouble 'ere trying to remove the last character of an NSString.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.