.net - Thumbrule on which collections have the Length or Count property - C# -
some c# collections have count , of them have length property. there thumbrule find out 1 has , why discrepency?
i'd general thumbrule following:
count
collections variable length, i.e. lists (fromicollection
)length
fixed length collections, i.e. arrays, or other immutable objects, i.e.string
.
update:
just elaborate count
comes through icollection
, doesn't indicate variability, example (as per greg beech's comment) readonlycollection<t>
has count
property not variable, implement icollection
.
perhaps more exact rule of thumb be:
count
indicates implementsicollection
length
indicates immutability.
Comments
Post a Comment