Does an empty array in .NET use any space?

后端 未结 9 1511
暗喜
暗喜 2021-01-01 10:39

I have some code where I\'m returning an array of objects.

Here\'s a simplified example:

string[] GetTheStuff() {
    List s = null;
             


        
9条回答
  •  执笔经年
    2021-01-01 11:20

    Declared arrays will always have to contain the following information:

    • Rank (number of dimensions)
    • Type to be contained
    • Length of each dimension

    This would most likely be trivial, but for higher numbers of dimensions and higher lengths it will have a performance impact on loops.

    As for return types, I agree that an empty array should be returned instead of null.

    More information here: Array Types in .NET

提交回复
热议问题