C# 使用For循环将值存储在列表中

C# 使用For循环将值存储在列表中,c#,C#,我试图将循环中的值存储在列表中。我的代码是: int count = 100; for(int i=0;i<=count;i++) { my code to get the text: m.gettextfromelement("xpath"); } int计数=100; 对于(inti=0;iList=newlist(); 整数计数=100; 对于(inti=0;i这是一种方法 var stringList = new List<string>(); //

我试图将循环中的值存储在列表中。我的代码是:

int count = 100;
for(int i=0;i<=count;i++)
{
    my code to get the text:
    m.gettextfromelement("xpath");
}
int计数=100;
对于(inti=0;i
List=newlist();
整数计数=100;

对于(inti=0;i这是一种方法

var stringList = new List<string>(); // The list to store your text
var count = 100;
for (var iteration = 0; iteration <= count; iteration++)
{
    //Code to get the text...
    //Code to get the specific element - var specificElement = m.gettextfromelement("xpath");
    //Finally, you "Add()" the specific element text to the list as...
    stringList.Add(specificElement);
}
var stringList=new List();//存储文本的列表
var计数=100;
对于(var迭代=0;迭代
var列表=新列表();
整数计数=100;

对于(int i=0;问题不清楚….errr….
List.Add
?您是否尝试过研究任何内容?我想保留文本(国家)从列表中的表列开始,然后根据字母顺序对其进行排序。我正在使用for循环获取这些值,但遇到了如何将这些值存储在列表或集合中的问题。您的代码仍然没有意义。另外,“列表中的表列”是什么意思?您是在使用
列表
还是某种数据库?这些代码将创建一个包含100个项目的列表,所有项目的值均为“StringValue”。“StringValue”是指他想在列表中输入的值(您引用了它),因此它将在每次循环时将该特定字符串插入列表。
var stringList = new List<string>(); // The list to store your text
var count = 100;
for (var iteration = 0; iteration <= count; iteration++)
{
    //Code to get the text...
    //Code to get the specific element - var specificElement = m.gettextfromelement("xpath");
    //Finally, you "Add()" the specific element text to the list as...
    stringList.Add(specificElement);
}
var list = new List<string>();
int count = 100;
for(int i=0;i<=count;i++)
{
    list.Add(m.gettextfromelement("xpath"));
}