ArrayList vs List<> in C#

后端 未结 12 2137
深忆病人
深忆病人 2020-11-22 04:10

What is the difference between ArrayList and List<> in C#?

Is it only that List<> has a type while ArrayLis

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 04:58

    As mentioned in .NET Framework documentation

    We don't recommend that you use the ArrayList class for new development. Instead, we recommend that you use the generic List class. The ArrayList class is designed to hold heterogeneous collections of objects. However, it does not always offer the best performance. Instead, we recommend the following:

    • For a heterogeneous collection of objects, use the List (in C#) or List(Of Object) (in Visual Basic) type.
    • For a homogeneous collection of objects, use the List class.
    • See also Non-generic collections shouldn't be used

      提交回复
      热议问题