C # array initialization in several ways

Fear of your life mediocrity, comforted their ordinary valuable

C # array initialization in several ways

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

namespace OneArray
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arrOld;                                //数组初始化的几种方式,注意赋值利用 {} 实现。
            arrOld=new int[5]{ 30, 32, 40, 25, 35 };       
            int[] arrOld1 = {30,20,212 };
            int[] arrOld2 = new int[4] { 1, 2, 3, 4 };
            int[] testArray=new int[10];
            for (int i = 0; i < 10; i++)
            {
                testArray[i] = i * 3;                    //对数组赋值前需要初始化数组长度
            }
            Console.WriteLine("员工年龄:");
            foreach (int n in arrOld)                     //使用foreach语句循环遍历一维数组中的元素
            {
                Console.WriteLine("{0}", n + "岁 ");     //输出数组中的元素
            }
            Console.ReadLine();
        }
    }
}

 Try to modify an array of small demo and found not even change out of grammar are not familiar with. Programming still have to get down to knock the code, remember unrealistic expectations is not enough light to read.

Guess you like

Origin blog.csdn.net/cxu123321/article/details/92560612