Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
This error is giving

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for 'System.Collections.ArrayList.this[int]' has some invalid arguments

Source Error:

<br />
Line 19:             {<br />
Line 20:                 al.Add(item);<br />
Line 21:                 string ss = al[item].ToString();<br />
Line 22:                 Response.Write(ss);<br />
Line 23:             }<br />


My first cs page is


protected void Button1_Click(object sender, EventArgs e)
    {
        ArrayList myAL1 = new ArrayList();
        myAL1.Add(txtId.Text.ToString());
        myAL1.Add(txtName.Text.ToString());
        string items = String.Join(",", ((string[])myAL1.ToArray(typeof(String))));
        string url = "ReceiveValueOfTextBoxSendingInLoop.aspx?items=" + items;
        Response.Redirect(url);
    }


My second cs code is

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["items"].ToString() != null)
        {

            string[] items = Request.QueryString["items"].ToString().Split(',');
            ArrayList al = new ArrayList();
            foreach (string item in items)
            {
                al.Add(item);
                string ss = al[item].ToString();
                Response.Write(ss);
            }
            //string ss = al[0].ToString();
            //string ss1 = al[1].ToString();
           
          //  Response.Write(ss);
           // Response.Write(ss1);
        }

    }
Posted
Updated 21-Dec-11 23:41pm
v2
Comments
thatraja 22-Dec-11 5:33am    

PLEASE TRY THIS....
C#
string[] items = Request.QueryString["items"].ToString().Split(',');
                  ArrayList al = new ArrayList();
                  foreach (string item in items)
                  {
                        al.Add(item);
                        string ss = al[0].ToString();
                        string ss1 = al[1].ToString();
                        Response.Write(ss);
                  }
 
Share this answer
 
Add the below namespace in your cs pages


C#
using System.Collections;
 
Share this answer
 
C#
string ss = al[item].ToString();

You are trying to use a string variable as an index where an integer is required.

[edit]
You should use the return value from the Add()[^] method.
[/edit]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900