zoukankan      html  css  js  c++  java
  • c# 聲明數組方法


        聲明數組方法有三種:

            //聲明數組方法1
            int[] arr={1,2,3};

            
    //聲明數組方法2
            int[] arr=new int[3];
            arr[
    0]=1;
            arr[
    1]=2;
            arr[
    2]=3;    

            
    //聲明數組方法3
     
         
    int[] arr=new int [ArrLenth];

        方法3比較特別,下例協助理解:

        static void Main()
        {
            
    int i=1;
            Console.WriteLine(
    "Please enter the array's length:");
            i
    =Int32.Parse(Console.ReadLine());
            PrintArr(i);
            Console.ReadKey();
        }
        
        
    static void PrintArr(int ArrLenth)    
        {
            
    //Án©ú¼Æ¤èªk3
            int[] arr=new int [ArrLenth];
            
    for    (int i=0;i<arr.Length;i++)
                arr[i]
    =i;
            Console.WriteLine(
    "Print Array's Value");
            
    for(int i=0;i<arr.Length;i++)
                Console.WriteLine(
    "arr[{0}]={1}",i,arr[i]);        
        }

  • 相关阅读:
    性能测试基础篇
    Jmeter参数化
    斐波那契
    Web安全 概述
    HTTP 协议详解
    echarts 响应式布局
    vue 结合mint-ui Message box的使用方法
    vue 中使用iconfont Unicode编码线上字体图标的流程
    手机端@media的屏幕适配
    @media响应式的屏幕适配
  • 原文地址:https://www.cnblogs.com/scottckt/p/1125655.html
Copyright © 2011-2022 走看看