In fact, there are only two reasons why you should ever use a structure, and this is either to get value type semantics, or to improve performance.
Since the structure contains an array, value type semantics do not work. When you copy the structure, you get a copy of count , but you only get a copy of the reference to the array, not a copy of the elements in the array. Therefore, you will have to use extreme caution whenever the structure is copied so that you do not receive conflicting instances.
So the only remaining valid reason will be performance. There is a small overhead for each instance of the reference type, so if you have a lot of them, there can be a noticeable increase in performance.
One of the great features of this structure is that you can create an array from them and you will get an array of empty lists without having to initialize each list:
ItemList<string>[] = new ItemList<string>[42];
Since the elements of the array are filled with zeros, the count member will be zero, and the items member will be null.
Guffa Jun 01 2018-11-11T00: 00Z
source share