如何在C Sharp中定义一维数组?
数组用于存储数据集合,但是将数组视为存储在连续内存位置的相同类型变量的集合通常会更有用。
定义一维数组-
int[] runs = new int[10];
现在让我们在同一行中初始化数组-
int[] runs = new int[5] {125, 173, 190, 264, 188};以下是显示如何声明,初始化和显示数组的示例-
示例
using System;
namespace Program {
class Demo {
static void Main(string[] args) {
int[] runs = new int[5] {125, 173, 190, 264, 188};
int i,j;
for (j = 0; j < 5; j++ ) {
Console.WriteLine("Innings score of Cricketer[{0}] = {1}", j, runs[j]);
}
Console.ReadKey();
}
}
}输出结果
Innings score of Cricketer[0] = 125 Innings score of Cricketer[1] = 173 Innings score of Cricketer[2] = 190 Innings score of Cricketer[3] = 264 Innings score of Cricketer[4] = 188
热门推荐
10 诗词送行祝福语大全简短
11 新房开工吉日祝福语简短
12 50多岁生日简短祝福语
13 安徽疫情祝福语简短英语
14 农民朋友发财祝福语简短
15 对生活祝福语简短精辟
16 搬家词简短祝福语朋友
17 女神结婚快乐祝福语简短
18 文学短句祝福语大全简短