Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
3.80/5 (3 votes)
See more:
What is the basic difference between Collection and Generics?
Posted

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[^]. :)

Regards
 
Share this answer
 
v2
Comments
Prashant Srivastava LKO 19-Dec-11 12:59pm    
Nice answer
Maybe it is similar to the difference between, say, searching the info with Google [^] or Bing [^]?
:rolleyes:
 
Share this answer
 
<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;
}
}
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900