Mid From PDF Collections C# Collections

How do non-generic collections like ArrayList and Hashtable differ from their generic counterparts (List<T>, Dictionary<TKey, TValue>)?

Feature Non-Generic Generic

Type Safety No Yes

Performanc

Slower (boxing/unboxing) Faster

Casting Required Not required

Syntax Less readable Clean and

type-specific

Examples:

// Non-generic

rrayList arr = new ArrayList();

rr.Add(1);

rr.Add("text"); // Allowed, but risky

// Generic

List<int> list = new List<int>();
list.Add(1);

// list.Add("text"); // Compile-time error

// Hashtable vs Dictionary

Hashtable ht = new Hashtable();
ht["id"] = 101;
Dictionary<string, int> dict = new Dictionary<string, int>();
dict["id"] = 101;

Real-world use case:

Generic collections are recommended for new development due to safety and performance.

Non-generic collections are often found in older legacy systems.

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details