What are the differences between Generics and Collections?

  • .NET provides Collection types which can be used to store and work on sequence of objects or data, with built-in utility methods.
  • Collections are like dynamic arrays - whose length is adjusted based on the number of elements that are being inserted into the types.
  • Collections are a part of the System.Collections namespace. These can accept any type of data without a constraint on the datatype being inserted. The elements inserted are of type Object.
  • Examples of Collections are IEnumerable, ICollection, ArrayList, HashTable, Stack, Queue etc.
  • Generics are similar to collections, but implemented using Type parameters.
  • Generic collections accept a type parameter and accept the elements of only those type for which the generic collection is instantiated. These enforce strict type checks.
  • Examples of Generic collections are List, Dictionary, Generic implementations of IEnumerable, Stack, Queue, LinkedList, HashSet etc.
  • The Generics are a part of the System.Collections.Generic namespace
  • .NET provides Collection types which can be used to store and work on sequence of objects or data, with built-in utility methods.
  • Collections are like dynamic arrays – whose length is adjusted based on the number of elements that are being inserted into the types.
  • Collections are a part of the System.Collections namespace. These can accept any type of data without a constraint on the datatype being inserted. The elements inserted are of type Object.
  • Examples of Collections are IEnumerable, ICollection, ArrayList, HashTable, Stack, Queue etc.
  • Generics are similar to collections, but implemented using Type parameters.
  • Generic collections accept a type parameter and accept the elements of only those type for which the generic collection is instantiated. These enforce strict type checks.
  • Examples of Generic collections are List, Dictionary, Generic implementations of IEnumerable, Stack, Queue, LinkedList, HashSet etc.
  • The Generics are a part of the System.Collections.Generic namespace
Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *