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]);        
        }

  • 相关阅读:
    c# 运算符 ? ??
    c# linq <未完>
    javasript this
    python3 闭包(一)
    dom 中的换行符
    (转)关于 awk 的 pattern(模式)
    linux note(1)
    python sqlite3
    python 特殊方法
    Go Example--锁
  • 原文地址:https://www.cnblogs.com/scottckt/p/1125655.html
Copyright © 2011-2022 走看看