When would you not use Generic Collections?

前端 未结 8 1869
醉酒成梦
醉酒成梦 2021-01-19 00:57

The advantage of using generics is that it increases the type safety - you can only put in the correct type of thing, and you get out the correct type without requiring a ca

8条回答
  •  春和景丽
    2021-01-19 01:24

    If you need to store arbitrary data, use List (or whatever). Then it's absolutely clear that it's deliberately arbitrary.

    Other than that, I wouldn't use the non-generic collections for anything. I have used IEnumerable and IList when I've been converting an object reference and didn't know the type to cast it to at compile-time - so non-generic interfaces are useful sometimes... but not the non-generic classes themselves.

    提交回复
    热议问题