arraylist 的 contains问题(在线等)
ArrayList categoryIDList = new ArrayList();string[] strKeyList = new string[2];
strKeyList[0] = row.Cells[1].Text;
strKeyList[1] = ((Label)row.Cells[4].FindControl("labType")).Text;
categoryIDList.add(strKeyList)
然后categoryIDList.Contains(strKeyList)
为什么每次都是返回false?
求教! --------------------编程问答-------------------- 怎么我这边测试是true呢?
categoryIDList.add(strKeyList)
里的add应该是Add,是不是你那儿执行,没有把strKeyList加到categoryIDList里? --------------------编程问答-------------------- 同一楼上的这里的结果也是
categoryIDList.Contains(strKeyList) true bool
不过,编译能通过??(add)
--------------------编程问答--------------------
ArrayList categoryIDList = new ArrayList();
string[] strKeyList = new string[2];
strKeyList[0] = "a";
strKeyList[1] = "b";
categoryIDList.Add(strKeyList);
bool a= categoryIDList.Contains(strKeyList);
我测试返回的也是true啊 --------------------编程问答-------------------- 我调了一下,结果也是很奇怪
明明categoryIDList是有个object的,而且就是和strKeyList一样,但是就是Contains老是返回假 --------------------编程问答-------------------- 原代码
#region//为保持翻页后checkbox状态,记录下当前状态
private void RememberOldValues()
{
ArrayList categoryIDList = new ArrayList();
foreach (GridViewRow row in dlResult.Rows)
{
//string strKeyList="";
//strKeyList = row.Cells[1].Text + ((Label)row.Cells[4].FindControl("labType")).Text;
//test
string[] strKeyList = new string[2];
strKeyList[0] = row.Cells[1].Text;
strKeyList[1] = ((Label)row.Cells[4].FindControl("labType")).Text;
//index = (int)dlResult.DataKeys[row.RowIndex].Value;
bool result = ((CheckBox)row.FindControl("chboxChoose")).Checked;
// Check in the Session
if (Session["CHECKED_ITEMS"] != null)
categoryIDList = (ArrayList)Session["CHECKED_ITEMS"];
if (result)
{
if (!categoryIDList.Contains(strKeyList))
categoryIDList.Add(strKeyList);
}
else
categoryIDList.Remove(strKeyList);
}
if (categoryIDList != null && categoryIDList.Count > 0)
Session["CHECKED_ITEMS"] = categoryIDList;
}
#endregion
#region//还原checkbox状态
private void RePopulateValues()
{
ArrayList categoryIDList = (ArrayList)Session["CHECKED_ITEMS"];
if (categoryIDList != null && categoryIDList.Count > 0)
{
foreach (GridViewRow row in dlResult.Rows)
{
//string strKeyList = "";
//strKeyList = row.Cells[1].Text + ((Label)row.Cells[4].FindControl("labType")).Text;
//test
string[] strKeyList = new string[2];
strKeyList[0] = row.Cells[1].Text;
strKeyList[1] = ((Label)row.Cells[4].FindControl("labType")).Text;
if (categoryIDList[0] == strKeyList)
{
CheckBox myCheckBox = (CheckBox)row.FindControl("chboxChoose");
myCheckBox.Checked = true;
}
}
}
}
#endregion
补充:.NET技术 , C#