C#获取数组的所有元素 [英] C# get all elements of array
本文介绍了C#获取数组的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用array.ElementAt(0);
我们可以在数组的索引0处获取元素.有没有一种方法可以获取数组中的所有元素?
Using array.ElementAt(0);
we can get the element at index 0 of the array. Is there a method to get all the elements in an array?
string[] arr1 = {'abc', 'def', 'ghi'}
Library.Results["TEST_ACTUALVALUE"] = "The results are: " + arr1;
TEST_ACTUALVALUE是我的report.xls文件中的一列.上面的代码在我的excel文件中写入了System.string [].
TEST_ACTUALVALUE is a column in my report.xls file. The above writes System.string[] in my excel file.
推荐答案
您已经拥有数组中的所有元素……数组本身.
You already have all of the elements in the array...the array itself.
简单的答案是遍历它们:
The simple answer is iterate over them:
foreach(var item in array)
{
// work with item here
}
或者,如果您希望处理索引:
Or if you'd rather deal with indexes:
for(var i = 0; i < array.Length; i++)
{
var item = array[i];
// work with item here
}
这篇关于C#获取数组的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文