码迷,mamicode.com
首页 > Windows程序 > 详细

c# 第四课 Arrays

时间:2015-04-07 19:35:30      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

Initializing Array Elements
    int[] myIntArray = new int[5] { 2, 4, 6, 8, 10 }; // longer syntax
    int[] myIntArray = { 2, 4, 6, 8, 10 };                      // shorter syntax

定义2行3列的int 类型的数组

int [ , ] myRectangularArray = new int[2,3];

The params  keyword allows you to pass in a variable number of parameters without necessarily explicitly creating the array.
 

初始化4行3列的int 类型的数组

           

const int rows = 4;    const int columns = 3;

            // imply a 4x3 array

            int[,] rectangularArray =

           {

                    {0,1,2}, {3,4,5}, {6,7,8}, {9,10,11}

           };

            for (int i = 0; i < rows; i++)

            {

                for (int j = 0; j < columns; j++)

                {

                    Console.WriteLine("rectangularArray[{0},{1}] = {2}",

                        i, j, rectangularArray[i, j]);

                }

            }

 

 

c# 第四课 Arrays

标签:

原文地址:http://www.cnblogs.com/GSONG/p/4399076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!