Mid
From PDF
Collections
C# Collections
How would you implement a generic collection in C# for a custom object?
Short answer: Define your custom object class. Create a collection class that holds objects of that type using generics or directly. Example: public class Employee
Example code
{
public int Id { get; set; }
public string Name { get; set; }
}
public class EmployeeCollection : Collection<Employee>
{ // You can add custom methods specific to Employee collection here } Or simply use List<Employee> directly for flexibility.
Real-world example (ShopNest)
Prefer List<Order> over ArrayList in ShopNest. Generics catch type mistakes at compile time and avoid boxing when you store ints or decimals.
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