如何操作列表? [英] How Do I Manipulate A List?
问题描述
我有这个列表的这一组。我已设法将其添加到列表中并将其显示在网格中。
现在我想选择列表中的前30个单词。这样做我遇到了一些问题。
我想用列表检查输入文本框的文本,如果文本已经存在于列表中,我想返回30个单词其中包括文字。
需要帮助。
提前致谢。
Hi,
I have this set of this list.I have managed to add it inside the list and display it into a grid.
Now I would like to select the top 30 words inside the list. I am encountering some problems in doing so.
I would like to check the text that are typed into the textbox with the list and if the text already exist in the list, I would like to return the 30 words which includes the text.
Help needed.
Thanks in advance.
string check = textbox.Text;
<pre lang="xml">List<string> duplicate = new List<string>();
if (duplicate.Contains(check) == true)
{
int remove = Math.Max(0, duplicate.Count - 28);
duplicate.RemoveRange(0, remove);
duplicate.Insert(5, check);
//duplicate.AddRange(final);
}</pre>
推荐答案
List<串GT; duplicate = new List< string>();
List<string> duplicate = new List<string>();
上面的语句创建一个空
列表,即 duplicate
包含NO项目。您应该使用 List< T>构造函数(IEnumerable< T>) [ ^ ] ctor,以使其成为原始版本的副本。
The above statement creates an empty
list, that is duplicate
contains NO items. You should use the List<T> Constructor (IEnumerable<T>)[^] ctor in order to make it a copy of the original one.
这篇关于如何操作列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!