编译错误------------ [英] Compilation Error ------------
问题描述
此错误正在给出
编译错误
说明:编译服务该请求所需的资源期间发生错误.请查看以下特定的错误详细信息,并适当地修改您的源代码.
编译器错误消息:CS1502:"System.Collections.ArrayList.this [int]"的最佳重载方法匹配具有一些无效的参数
源错误:
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 />
我的第一个CS页面是
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);
}
我的第二个CS代码是
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);
}
}
推荐答案
请尝试一下....
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);
}
在您的CS页面中添加以下名称空间
Add the below namespace in your cs pages
using System.Collections;
string ss = al[item].ToString();
您试图将string
变量用作需要整数的索引.
[edit]
您应该使用 Add()
[ ^ ]方法.
[/edit]
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]
这篇关于编译错误------------的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!