如何遍历C#中数组的所有元素?
首先,设置一个数组并初始化它-
int[] arr = new int[] {34, 56, 12};遍历数组的所有元素-
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine(arr[i]);
}让我们看完整的代码-
示例
using System;
public class Program {
public static void Main() {
int[] arr = new int[] {34, 56, 12};
//长度
Console.WriteLine("Length:" + arr.Length);
for (int i = 0; i< arr.Length; i++) {
Console.WriteLine(arr[i]);
}
}
}热门推荐
10 老考试顺利祝福语简短
11 新老师祝福语 简短独特
12 冬季祝福语大全 简短的
13 客户入住新房祝福语简短
14 白羊生日祝福语 简短独特
15 网络段子祝福语大全简短
16 父亲简短结婚祝福语大全
17 高考已上岸祝福语简短
18 步入高中祝福语简短励志