清单和清除方法存在问题:

|
Dictionary<string, List<DisplayAllQuestionsTable>> tPages= new Dictionary<string, List<DisplayAllQuestionsTable>>();;
List<DisplayAllQuestionsTable> threadsByTopic = new List<DisplayAllQuestionsTable>();
int tPage=0;
        foreach (var topicKeys in postsByTopic)
        {

               if (topicKeys.Key == subTopic)
                {
                    foreach (var item in postsByTopic[topicKeys.Key])
                    {
                        questionNumber++;
                        maximumTopicPages++;
                        threadsByTopic.Add(item);//Adds All DisplayAllTables objects
                        //if there are 20 add a button.
                        if (maximumTopicPages == 20)
                        {
                            tPages.Add(tPage.ToString(), threadsByTopic);//The threadsByTopic clears everytime i call threadsByTopic.clear()

                            threadsByTopic.Clear();
                            tPage++;

                    }
                }
我知道,如果它是一个引用,则它的引用是按值传递的。但是,如果我将其threadByTopic列表添加到字典中,是否按原样保存...?还是必须重置?     
已邀请:
        该实例已添加到字典中,但其列表仍然相同,因此当您使用clear时,会清除您刚刚添加的列表。 U应该创建新的列表对象,而不要使用clear。     

要回复问题请先登录注册