我们要存储玩游戏的的10次得分,我们通常会这样操作:
int score1 = 34;
int score2 = 32;
int score3 = 56;
...
int score10 = 64;
很显然这样一个一个数列举和赋值,效率是特别低的,而且使用起来也不方便,所以这个时候,我们会使用到数组的概念,数组对于管理和操作大量的数据具有特别大的优势。
数组的定义
<baseTtype>[] <name>;
实例:
int[] scores; //声明了int类型的分数数组
数组的初始化(赋值)
第一种方式:
int[] scores = {34, 34, 3, 45, 33, 3,...};
第二种方式:
scores = new int[10];
第三种方式:
scores = new int[10]{123, 12, 43, 231, 23, 12, 23,13, 112, 14};
数组的初始化
<arrayName>[条目索引]
存储玩游戏的的10次得分
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] scores = {23,23,44,12,12,63,12,34,12,23};
}
}
}