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

  • 相关阅读:
    正则表达式学习1
    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
    (转)DBUS基础知识
    WakeLock的使用
    观察者模式
    Notification的使用
    Head First 设计模式之入门
    (转)Android WebView总结
    书架也是一根筋
    PendingIntent分析
  • 原文地址:https://www.cnblogs.com/shawnzhou/p/3321914.html
Copyright © 2011-2022 走看看