清除列表但保留会话

时间:2015-06-13 06:47:09

标签: c# list session

我有一个带有列表的代码,如图所示

var refinedClaimSearchNew = new ClaimSearch();
for (int i = 1; i < refineDictionary.Length; i++)
{
    List<ClaimSearchDataValues> claimTable = new List<ClaimSearchDataValues>();
    int count = i; 
    if (count == 1) { claimTable = refinedClaimSearch.RowValues; }
    else { //My problem is in this else loop
           claimTable = (List<ClaimSearchDataValues>)Session["Test"];//Get the list out of session
           if (refinedClaimSearchNew.RowValues != null) { refinedClaimSearchNew.RowValues.Clear(); //And then clear the list but retain session value} 
         }

    var dictionaryItems = refineDictionary[i];
    string[] dictionaryItemsSplit = dictionaryItems.Split(',');

    for (int j = 1; j < dictionaryItemsSplit.Length; j++)
    {
       var nodeElement = dictionaryItemsSplit[j];
       foreach (var row in claimTable)
       {
          var currentRow = row;
          bool hasRefineValue = false;
          foreach (var rowValues in currentRow.CellValues)
          {
              if (rowValues.Key == nodeElement || rowValues.Value == nodeElement)
              {
                  hasRefineValue = true;
              }
          }
          if (hasRefineValue == true)
          {
             refinedClaimSearchNew.RowValues.Add(currentRow);
          }
       }
    }
    Session["Test"] = refinedClaimSearchNew.RowValues;//storing list in session
}

我在会话中存储一个列表,对于下一次迭代,我想从会话中删除存储的列表,但同时清除列表以便我可以再次使用新列表。 但看起来当我从会话中取出列表 - 它很好,下一行当我清除()列表时,从会话中检索的列表也变为0 .. 请帮我知道怎么做....

0 个答案:

没有答案