How do non-generic collections like ArrayList and Hashtable differ from their generic counterparts (List<T>, Dictionary<TKey, TValue>)?
Short answer: 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 ArrayList arr = new ArrayList(); arr.Add(1); arr.Add("text"); // Allowed, but risky // Generic List<int> list = new List<int>(); dict["id"] = 101; Real-world use case: Generic collections are recommended for new development due…
Explain a bit more
to safety and performance. Non-generic collections are often found in older legacy systems.
Example code
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>();
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png