I want to know which one is the best way to accomplish this task.
As always in programming, people without knoledge are looking for a simple solution. There's nothing here. Look, there is a difference in performance, it does not matter for a given task (too little data).
In general, an array is faster, but has serious problems with other elements. ininsert / delete is slower since all elements must be copied to a new array.
The list does not have a copy problem, but each record is a node, which means much more memory usage and much more memory - each record is your object + node object with pointers back and forth to the next / last element. This makes random access slower, sometimes significantly. Not a problem if you ONLY do foreach, especially with 7 elements. This is much more if you have thousands of access to a list of 250,000 items.
Part of your programming training is understanding the standard features of EVERY element on the list. The above question is an entry-level beginner question - one that I like to use in a programmer's interview to get rid of wannabes.
source share