数组

数组:解决同一类大量数据在内存存储和运算的功能    

分类:一维数组、二维数组、三维数组     

特点:连续,同一类数据   一维数组:

定义:指定类型,指定长度,指定名称 int[] a=new int[5]; 创建一个int类型的数组,长度是5,从1开始   new是动词

int[] a=new int[5]{90,95,93,92,97};

int[] a=new int[5]{90,95,93};会把前三个元素赋值,后两个元素保持默认值0

int[] a=new int[]{90,95,93,92,97};计算机会根据后面的赋值,动态计算数组的长度

赋值: 数组名[下标数值]=值

取值: 数组名[下标数值],下标从0开始

console.writeline(a[3]+a[0]);

数组的好处: 1、对于大量数据来说,保存的时候,定义一个数组即可解决

                  2、用循环来控制数组的下标,可以对数组进行批量操作

例:            

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a=new int[5];
            for (int i = 0; i < 5; i++)//批量赋值
            {
                a[i] = (i + 1) * 10;
            }
            for (int j = 0; j < 5; j++)//批量取值
            {
                Console.WriteLine(a[j]);
            }
            Console.ReadLine();
        }
    }
}

 

posted @ 2015-06-19 15:46  蓝瑟黄昏  阅读(97)  评论(0编辑  收藏  举报