zoukankan      html  css  js  c++  java
  • 二维数组、齿形数组和游长变元表

    实例学习,代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TwoDimensionArray
    {
        class Program
        {
            public static void OutputArray(int[,] array)
            {
                for (int i = 0; i < array.GetLength(0); i++)
                {
                    for (int j = 0; j < array.GetLength(1); j++)
                    {
                        Console.Write("{0}", array[i, j]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
    
            public static void OutputJaggedArray(int[][] array)
            {
                foreach (var row in array)
                {
                    foreach (var element in row)
                    {
                        Console.Write("{0}", element);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
    
            public static double ParamsArray(params double[] param)
            {
                double total = 0.0;
                foreach (var element in param)
                {
                    total += element;
                }
                return total;
            }
    
            static void Main(string[] args)
            {
                int[,] rectangular = { { 1, 2, 3 }, { 4, 5, 6 } };
                int[][] jagged ={new int[]{1,2},
                                 new int[]{3},
                                 new int[]{4,5,6}};
                OutputArray(rectangular);
                OutputJaggedArray(jagged);
    
                double[] paraArray = new double[] { 1, 2, 3 };
                Console.Write("{0}
    ", ParamsArray(paraArray));
    
                Console.ReadLine();
            }
        }
    }

    输出结果如下:

    image

  • 相关阅读:
    [BZOJ5015][Snoi2017]礼物
    [BZOJ5016][Snoi2017]一个简单的询问
    [BZOJ4184]shallot
    上传头像
    前端基础之jQuery
    前端之html的查漏补缺
    CSS3圆角、阴影、rgba
    CSS3新增选择器
    前端基础之BOM和DOM
    前端基础之JavaScript
  • 原文地址:https://www.cnblogs.com/shawnzhou/p/3321914.html
Copyright © 2011-2022 走看看