码迷,mamicode.com
首页 > 编程语言 > 详细

8. C# -- 一维数组,二维数组,锯齿数组

时间:2015-05-12 19:12:40      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:c#

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)
{
            //声明一维数组,并输出
            Console.WriteLine("ouput  array.");
            string []friendNames = {"robert","mike","jeremy" };
            int i;
            Console.WriteLine("here are {0} of my friends", friendNames.Length);
            for (i = 0; i < friendNames.Length;i++ )
{
                Console.WriteLine(friendNames[i]);
}
            Console.WriteLine("ouput double array.");
            //声明二维数组,并输出
            double[,] hillheight = { {1,2,3,4},{5,6,7,8}};
            foreach (double height in hillheight)
{
                Console.WriteLine("{0}",height);
}
            Console.WriteLine("ouput divisor array.");
            //声明锯齿数组,数组的数组
            //divisor1To10,用于保护int[]元素,而不是int元素;
            //需要对int[]元素进行遍历
            int[][] divisor1To10 = {
                                      new int []{1},
                                      new int []{1,2},
                                      new int []{1,3},
                                      new int []{1,2,4},
                                      new int []{1,5},
                                      new int []{1,2,3,6},
                                      new int []{1,7},
                                      new int []{1,2,4,8},
                                      new int []{1,3,9},
                                      new int []{1,2,5,10}
};
            foreach (int[] divisorOfInt in divisor1To10)
{
                foreach (int divisor in divisorOfInt)
{
                    Console.WriteLine(divisor);
}
}
            Console.ReadLine();
 
}
}
}


本文出自 “Ricky's Blog” 博客,请务必保留此出处http://57388.blog.51cto.com/47388/1650618

8. C# -- 一维数组,二维数组,锯齿数组

标签:c#

原文地址:http://57388.blog.51cto.com/47388/1650618

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