Monday, February 4, 2013

C# Best Practices - Array vs Tuple

Several times I have asked myself when to use a list, array, or tuple. This depends on what you are storing.

If you are creating a homogeneous collection of fixed length, then an array is desirable.
If you want a collection whose values are of variable length, a List allows for more optimal memory allocation as the length is dynamically allocated based on the values. A list has more functionality than an array. (need examples).
If you are creating a heterogeneous collection, then a tuple is desirable.




REFERENCE
http://stackoverflow.com/questions/1708510/python-list-vs-tuple-when-to-use-each
http://stackoverflow.com/questions/3306854/generic-list-vs-array