Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

I want to inizialize a new int array.

What are the advantages of:

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?

like image 967
Mafii Avatar asked Feb 03 '26 15:02

Mafii


1 Answers

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         
like image 167
Bill Tür stands with Ukraine Avatar answered Feb 05 '26 05:02

Bill Tür stands with Ukraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!