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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have code written that converts my Document to a string prior to printing
Before posting my question, I would like to tell you that I have no
i am trying to create a custom solution for a client using their prior
I have prior experience in build a automatic build process for .NET & Delphi
So, let's say I want to write a class that operates on different kinds
Duplicate of 249087 I have a bunch of user generated addresses that may contain
We recently upgraded our PHP and apache versions on our server. Prior to this
I recently upgraded a Flex 3 project to Flex 4 MX Only and prior
Iam not able to get familiar with XAMPP interface on Windows7 (Only prior experiencxe
In my code I am using a UISegmentedControl as a button with only ONE

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.