将'foreach'循环的每个值存储到字符串数组中

时间:2013-03-26 22:00:50

标签: c#

考虑:

 string[] collection = new string[3]{"hi","hello","test"}; 
 string [] elements = new string [3];
 int index = 0;
 foreach(string anode in collection)
 {
   string[index++] = anode;
 }

1 个答案:

答案 0 :(得分:4)

https://stackoverflow.com/a/599373/1618257

List<string> elements = new List<string>();
foreach(xmlnode anode in somecollection)
{
  elements.Add("string");
}