要访问循环之外的东西,只需在循环之外声明它,然后在循环处理完成后使用它:
string[] arr = ... for (int z = 0; z < alParmValues.Count; z++) { // work with arr... } var item = arr[3]; // Accessed outside of loop.
但是,您的代码似乎有些问题.我建议稍微考虑一下循环体和你想要做的事情.考虑这一行,例如:
for (int z = 0; z < alParmValues.Count; z++) { // ... string[] asd = alParmValues[z].ToString().Split(','); // There aren't any more references to asd after this point in the loop, // so this assignment serves no purpose and only keeps its last assigned // value. }
这项任务毫无意义; 每次进行循环时,只需覆盖之前的值asd
,就不会在循环中使用它.
要访问循环之外的东西,只需在循环之外声明它,然后在循环处理完成后使用它:
string[] arr = ... for (int z = 0; z < alParmValues.Count; z++) { // work with arr... } var item = arr[3]; // Accessed outside of loop.
但是,您的代码似乎有些问题.我建议稍微考虑一下循环体和你想要做的事情.考虑这一行,例如:
for (int z = 0; z < alParmValues.Count; z++) { // ... string[] asd = alParmValues[z].ToString().Split(','); // There aren't any more references to asd after this point in the loop, // so this assignment serves no purpose and only keeps its last assigned // value. }
这项任务毫无意义; 每次进行循环时,只需覆盖之前的值asd
,就不会在循环中使用它.