ArrayList versus List

6

What's the point in C # should we give preference to using List instead of ArrayList ?

    
asked by anonymous 09.08.2017 / 15:01

2 answers

8

Because List is generic and ArrayList is not. The data type of ArrayList is a object , ie it can by anything in it. In static languages this is not appropriate, you lose type security, you can no longer trust the contents of the list. Already List<T> determines what type you can put on it , then all of the code is trusted that it will only have elements of that particular type and derived types of it that are obviously compatible with this type. The compiler itself can ensure type security.

It's not just security, it's performance, too. This prevents casting and

09.08.2017 / 15:12