Skip to content

Instantly share code, notes, and snippets.

@aloisdg
Last active August 20, 2019 15:11
Show Gist options
  • Save aloisdg/8e75584fec670fb9ead2c8d90b34b56c to your computer and use it in GitHub Desktop.
Save aloisdg/8e75584fec670fb9ead2c8d90b34b56c to your computer and use it in GitHub Desktop.

Please stop using new T[0] to initialize an empty array


If you want an empty enumerable (and I know you should use one), you have Enumerable.Empty:

var a = Enumerable.Empty<T>();

If you face a case where you really need an empty array, you have Array.Empty:

var a = Array.Empty<T>();

If Enumerable.Empty wont work for you and Array.Empty is not a solution because you are locked in an old .NET version, well fine:

var a = new T[]{};

So please stop using new T[0], we are not golfing here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment