Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This Error is giving


C#
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:

 

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


My cs code is


JavaScript
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);
    }
Posted
Updated 21-Dec-11 23:16pm
v2

It is not possible to be sure what your problems is: if I include both your code fragments in am app and make senisble decisions as to what the undeclared parts are:

C#
TextBox txtId = new TextBox();
TextBox txtName = new TextBox();
ArrayList al = new ArrayList();
int item;
Then I do not get a compilation error.
How does my code differ from yours?
 
Share this answer
 
Comments
Janardan Pandey 22-Dec-11 5:23am    
ok i am pasteing second page code



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);
}

}


please give me reply
OriginalGriff 22-Dec-11 5:43am    
You can't access an ArrayList by the member itself! It doesn't know how to identify it - and it would be pretty silly, because you would be accessing the value you are using to select the item from the array.
Why not just use
string ss = item.ToString();
Which (in this case) is the equivalent of:
string ss = item;
since item is a string already...
In this code..

C#
al.Add(item);
string ss = al[item].ToString();//ERROR LINE
Response.Write(ss);


the value of item should be integer.

try by this..

C#
al.Add(item);
string ss = al[Convert.ToInt32(item)].ToString();//ERROR LINE
Response.Write(ss);


hope this helps..
 
Share this answer
 
Comments
Janardan Pandey 22-Dec-11 5:34am    
This is Not working and error is giving

Server Error in '/testing' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 23:
Line 24: al.Add(item);
Line 25: string ss = al[Convert.ToInt32(item)].ToString();//ERROR LINE
Line 26: Response.Write(ss);
Line 27: }

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