使用array.ElementAt(0);我们可以获取数组索引0处的元素.有没有一种方法来获取数组中的所有元素?
string[] arr1 = {'abc', 'def', 'ghi'}
Library.Results["TEST_ACTUALVALUE"] = "The results are: " + arr1;
Run Code Online (Sandbox Code Playgroud)
TEST_ACTUALVALUE是我的report.xls文件中的一列.上面在我的excel文件中写了System.string [].
Jus*_*ner 14
你已经拥有了数组中的所有元素......数组本身.
简单的答案是迭代它们:
foreach(var item in array)
{
// work with item here
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您更愿意处理索引:
for(var i = 0; i < array.Length; i++)
{
var item = array[i];
// work with item here
}
Run Code Online (Sandbox Code Playgroud)
通过"获取数组中的所有元素"很难知道你的意思,因为你已经拥有数组中的所有元素....
如果你的意思是从字符串数组中连接一个字符串,那么类似于:
var concatinatedString = String.Concat(myArrayOfStrings);
Run Code Online (Sandbox Code Playgroud)
有一百种方法可以给那只猫剥皮。在很大程度上,它应该取决于您希望对所有元素做什么。这是老派的 for 循环方法:
for(int i = 0; i < array.Length; i++)
{
something = array[i];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63695 次 |
| 最近记录: |