Empty arrays are not used often as arrays usually are about the presence data, not about the absence.
Here are two ways based on the int data type in C# (the original [WayBack] examples [WayBack] are using string, but since string itself is also a kind of array…):
Specify a size of zero:
int[] a = new int[0];
Specify an empty initialisation:
int[] a = new int[] { };
Though many people think arrays are a thing of the past, I think it is one of the first generic types and have their place. For one, enumerating over arrays using foreach is a lot faster in many environments than enumerating over other data types. Another thing is that the fixed nature of arrays can be very beneficial in setting constraints.
That’s why I like the balanced view from Eric Lippert [WayBack] in Arrays considered somewhat harmful – Fabulous Adventures In Coding – Site Home – MSDN Blogs [WayBack]
–jeroen
via: