Click here to Skip to main content
11,414,234 members (71,518 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
What is the basic difference between Collection and Generics?
Posted 25-Feb-10 21:18pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Briefly, the basic difference between generic and non-generic collections:

- Non-Generic collections - These are the collections that can hold elements of different data types. It holds all elements as object type.
So it includes overhead of type conversions.

- Generic collections - These are the collections that can hold data of same type and we can decide what type of data that collections can hold.

Some advantages of generic collections - Type Safe, Secure, reduced overhead of type conversions.

You can read more about generics here[^]. Smile | :)

Regards
  Permalink  
v2
Comments
Prashant Srivastava LKO at 19-Dec-11 12:59pm
   
Nice answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Maybe it is similar to the difference between, say, searching the info with Google [^] or Bing [^]?
Roll eyes | :rolleyes:
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<b><u>Here is the exmaple of the Generic collections
</u></b>


public class MyCustomList<MYTYPE>
{
   private ArrayList m_list = new ArrayList();
   public int Add(myType value)
   {
      return m_list.Add(value);
   }

   public void Remove(myType value)
   {
      m_list.Remove(value);
   }

   public myType this[int index]
   {
      get
      {
         return (myType)m_list[index];
      }
      set
      {
         m_list[index] = value;
      }
   }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,130
1 OriginalGriff 7,477
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web03 | 2.8.150427.2 | Last Updated 28 Feb 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100