如何操作列表 [英] How Do I Manipulate The List
本文介绍了如何操作列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个List< string>。在里面我有一个字符串文本的集合。
我想操纵列表删除所有文本,除了已输入文本框的文本。
我该怎么做?
需要帮助。在此先感谢。
Hi,
I have a List<string>. Inside it I have a collection of string texts.
I would like to manipulate the list into delete all the text except the text that have been typed into the textbox.
How do I do that?
Help needed. Thanks in advance.
List<string> final = new List<string>();
foreach (KeyValuePair<string, int> entry in sortDict)
final.Add(entry.Key);
final.RemoveAt(2);
List<string> duplicate = final.ToList();
//string check = textbox1.Text;
if (duplicate.Contains(check) == true)
{
int remove = Math.Max(0, final.Count - 27);
final.RemoveRange(0, remove);
int delete = Math.Max(0, duplicate.Count - 3);
duplicate.RemoveRange(3, delete);
// delete all the text in the string except check
duplicate.AddRange(final);
}
推荐答案
这篇关于如何操作列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文