Hi friends,
I want to know that what's the difference between collection and generic collection? Please explain in the programming scenario?
Collection in C#
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 8, 2012, 6:34 AM EST
This means that, when retrieving elements of the collection, you have to cast them to their actual type before you can use them as such.
It also means that when you store value types (int, double, char, bool etc) they have to be boxed on the heap when storing them and unboxed (by casting) when you retrieve them, which is a relatively slow process.
In contrast the generic collection classes in the System.Collections.Generic namespace are strongly typed which implies that they store everything internally as its actual type. List
This means that no casting is required when retrieving elements from generic collections and no boxing is required for value types which makes them more performant in that respect.