如果不用的话,大的List中会有很多重复的内容,这该怎么办?

例如有一个很多行的TXT,想读取其中几段放入list,然后把这几段的list放入一个大的List,重复几次
但是循环中,如果使用了list.clear会把之前放入List的内容也都清除。

宝慕林4294392
浏览 75回答 2
2回答

哔哔one

foreach(list<string> in 大list){对单个list<string>进行操作}你是这个意思??

翻过高山走不出你

List<List<string>>&nbsp;big_lst=new&nbsp;List<List<string>>();List<string>&nbsp;lst=new&nbsp;List<string>();//假如你每2行放一个list里面,在把这个lst放到大的list里面:int&nbsp;index=0;while(s.ReadLine()){&nbsp;&nbsp;if(index==2)&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;index=0;&nbsp;&nbsp;&nbsp;&nbsp;big_lst.Add(lst);&nbsp;&nbsp;&nbsp;&nbsp;lst=new&nbsp;List<string>();//重新创建集合(可以理解为清空集合)&nbsp;&nbsp;}else&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;lst.Add("你的数据");&nbsp;&nbsp;}}
打开App,查看更多内容
随时随地看视频慕课网APP