What is difference between these two array declarations?

前端 未结 5 1996
自闭症患者
自闭症患者 2021-01-11 21:05

It seems these two declarations are the same:

int[] array1 = {11, 22, 33};

and

int[] array2 = new int[] {11, 22, 33};
         


        
5条回答
  •  耶瑟儿~
    2021-01-11 21:33

    The both are exactly the same

    look this code:

    int[] arr1={1,2,3,4};
    int[] arr2= new int[]{1,2,3,4};
    

    using the reflector the both converted to the following:

    int[] expr_07 = new int[]
                {
                    1, 
                    2, 
                    3, 
                    4
                };
                int[] expr_19 = new int[]
                {
                    1, 
                    2, 
                    3, 
                    4
                };
    

提交回复
热议问题