Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 32741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:48:39+00:00 2026-05-10T13:48:39+00:00

Prior to C# generics, everyone would code collections for their business objects by creating

  • 0

Prior to C# generics, everyone would code collections for their business objects by creating a collection base that implemented IEnumerable

IE:

public class CollectionBase : IEnumerable 

and then would derive their Business Object collections from that.

public class BusinessObjectCollection : CollectionBase 

Now with the generic list class, does anyone just use that instead? I’ve found that I use a compromise of the two techniques:

public class BusinessObjectCollection : List<BusinessObject> 

I do this because I like to have strongly typed names instead of just passing Lists around.

What is your approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:48:40+00:00Added an answer on May 10, 2026 at 1:48 pm

    I am generally in the camp of just using a List directly, unless for some reason I need to encapsulate the data structure and provide a limited subset of its functionality. This is mainly because if I don’t have a specific need for encapsulation then doing it is just a waste of time.

    However, with the aggregate initializes feature in C# 3.0, there are some new situations where I would advocate using customized collection classes.

    Basically, C# 3.0 allows any class that implements IEnumerable and has an Add method to use the new aggregate initializer syntax. For example, because Dictionary defines a method Add(K key, V value) it is possible to initialize a dictionary using this syntax:

    var d = new Dictionary<string, int> {     {'hello', 0},     {'the answer to life the universe and everything is:', 42} }; 

    The great thing about the feature is that it works for add methods with any number of arguments. For example, given this collection:

    class c1 : IEnumerable {     void Add(int x1, int x2, int x3)     {         //...     }      //... } 

    it would be possible to initialize it like so:

    var x = new c1 {     {1,2,3},     {4,5,6} } 

    This can be really useful if you need to create static tables of complex objects. For example, if you were just using List<Customer> and you wanted to create a static list of customer objects you would have to create it like so:

    var x = new List<Customer> {     new Customer('Scott Wisniewski', '555-555-5555', 'Seattle', 'WA'),     new Customer('John Doe', '555-555-1234', 'Los Angeles', 'CA'),     new Customer('Michael Scott', '555-555-8769', 'Scranton PA'),     new Customer('Ali G', '', 'Staines', 'UK') } 

    However, if you use a customized collection, like this one:

    class CustomerList  : List<Customer> {     public void Add(string name, string phoneNumber, string city, string stateOrCountry)     {         Add(new Customer(name, phoneNumber, city, stateOrCounter));     } } 

    You could then initialize the collection using this syntax:

    var customers = new CustomerList {     {'Scott Wisniewski', '555-555-5555', 'Seattle', 'WA'},     {'John Doe', '555-555-1234', 'Los Angeles', 'CA'},     {'Michael Scott', '555-555-8769', 'Scranton PA'},     {'Ali G', '', 'Staines', 'UK'} } 

    This has the advantage of being both easier to type and easier to read because their is no need to retype the element type name for each element. The advantage can be particularly strong if the element type is long or complex.

    That being said, this is only useful if you need static collections of data defined in your app. Some types of apps, like compilers, use them all the time. Others, like typical database apps don’t because they load all their data from a database.

    My advice would be that if you either need to define a static collection of objects, or need to encapsulate away the collection interface, then create a custom collection class. Otherwise I would just use List<T> directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario - I have an SSIS job that depends on another prior
In prior versions of Windows before Vista you could have a Windows Service interact
I am attempting to determine prior art for the following idea: 1) user types
Background: I need to reserve an amount of memory below 0xA0000 prior to my
We are currently researching ways of enhancing image quality prior to submission to OCR.
Surely there is a way to store a date value prior than 1-1-1900 in
I am trying to execute this SQL query prior to restoring a .BAK file
Is there any easy/general way to clean an XML based data source prior to
Is it possible to have a CSS rule which basically undoes a prior rule?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.