[英]Removing an element in string list in c#, gives error(ArgumentOutOfRangeException)
[英]ArgumentOutOfRangeException when writing C# List<string> to multiple textbox
如何將列表放到多個TextBoxes? 我試圖用幾種方法來做到這一點。 它們都只能將List<string>
一個值放入TextBox中,並顯示System.ArgumentOutOfRangeException
錯誤
下面是到目前為止我嘗試過的代碼:
List<string> txtlist = new List<string>();
for (int ix = 1; ix < 16; ix++)
{
string test = command.Get(appendCommand);
txtlist.Add(test);
txt_1.Text = txtlist.ElementAt(0);
txt_2.Text = txtlist.ElementAt(1); //System.ArgumentOutOfRangeException
txt_3.Text = txtlist.ElementAt(2);
txt_4.Text = txtlist.ElementAt(3);
...
txt_4.Text = txtlist.ElementAt(15);
}
列表txtlist數據顯示如下:
[0]“ test1” [1]“ test2” [2]“ test3” .... [15]“ test16”
我想一一列出到文本框中,請給我看一些例子,謝謝。
首先建立txtList,然后建立項目。 不再有ArgumentOutOfRangeException
List<string> txtlist = new List<string>();
for (int i = 0; i < 16; i++)
{
string test = command.Get(appendCommand);
txtlist.Add(test);
}
txt_1.Text = txtlist.ElementAt(0);
txt_2.Text = txtlist.ElementAt(1);
txt_3.Text = txtlist.ElementAt(2);
txt_4.Text = txtlist.ElementAt(3);
...
txt_4.Text = txtlist.ElementAt(15);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.