问题是我想使用"共享内存"在处理程序中返回给定的许多整数值的平均值,但此代码不起作用,我该怎么办?
public void ProcessRequest(HttpContext context) {
ArrayList al=new ArrayList();
HttpResponse response=context.Response;
HttpRequest request=context.Request;
string x=request.UserHostAddress;
if (int.Parse(request.QueryString["i2"])==0) {
if (context.Items[x]==null) {
al.Add(request.QueryString["i1"]);
context.Items.Add(x, al);
}
else {
al=(ArrayList)context.Items[x];
al.Add(request.QueryString["i1"]);
}
response.Redirect("/Punto2.html");
}
else if(int.Parse(request.QueryString["i2"])==1) {
if (context.Items[x]==null)
response.Write("<h1>The ArrayList is null.</h1>");
else {
al=(ArrayList)context.Items[x];
float a=0;
for (int i=0; i<al.Count; i++) {
a+=(int)al[i];
}
a/=2;
//response.Write("<h1>"+al.Count+"</h1>");
response.Write("<h1>Average: "+a+"</h1>");
}
}
}