Is there any difference between new int [0] and new int [] {}

I want to initialize a new int array.

What are the advantages:

var myNewArray = new int[]{};

      

and

var myNewArray = new int[0];

      

Which one should I prefer over the other, or is it just a matter of code style?

+3


source to share


1 answer


There is no difference. Both produce the same IL:



IL_0000:  nop         
IL_0001:  ldc.i4.0    
IL_0002:  newarr      System.Int32
IL_0007:  stloc.0     // myNewArray
IL_0008:  ret         

      

+9


source







All Articles