Reputation: 86155
Will the above still create one element?
Upvotes: 2
Views: 5387
Reputation: 57220
It's a simple empty array, just like an empty list or generically an empty collection.
The only difference is that you can't modify it later by adding elements.
It could be really useful for example when a method returns an array as result.
When the method has no results, instead of returning null
you can return an empty array, so in the calling code you can skip a useless null
check and go directly on the enumeration.
Upvotes: 9
Reputation: 17216
No.
You'll get an IndexOutOfRangeException if you try to add anything to that array.
Upvotes: 11