In C# for example, arrays have Length property. But other collection types like lists, etc. have Count property. Is there a reason why these two are different? If so I would like to know.
closed as primarily opinion-based by gbjbaanb, user40980, durron597, gnat, user53019 Aug 26 '15 at 17:25
Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.
They are named differently because semantically they are quite different:
A collection's Count is the number of items currently stored in it and can potentially change over time.
An array's Length is the maximum number of items it can hold (it will have a length of 10 even if you haven't stored that many items in it) and is immutable.
If I have a bucket that can fit a maximum of 100 balls in it it has a Length of 100. If I put 50 balls into it it then it has a Count of 50.
If I add 10 more balls the Count becomes 60 but the Length is still 100. In order to change the Length I need to get a different bucket.
Array probably uses the word Length because under the hood it's allocating a contiguous block (a length) of memory based on the capacity multiplied by the item size. Although the fact that the List class uses "Capacity" for a similar (though mutable) concept suggests array may use the word "Length" for historical reasons.