Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does an list of lists smell bad, what are my other options

Tags:

c#

.net-2.0

I need to assemble an list of lists, but the whole idea doesn't sound too pretty. It just sounds so cumbersome. is there some other pattern for holding a list of lists.

my first though is to use an arrayList of Arraylist.

c#, .net-2

more: then number of items to be stored is small but always changing.

NOTE: I was corrected on the use of ArrayLists on this Question:

What's wrong with using an ArrayList in .net-2.0

like image 561
fishhead Avatar asked Dec 13 '22 20:12

fishhead


2 Answers

There's nothing wrong with List<List<T>> - LINQ's SelectMany can be your friend in that situation.

like image 179
Stephen Cleary Avatar answered Dec 15 '22 10:12

Stephen Cleary


How about using objects created in custom classes?

For example, Customers can have multiple Addresses. Create a Customer object which has an Address property. Then, you can have a collection (array, ArrayList, etc) of Customers, and each Customer can have a collection of Addresses.

This fits many kinds of information, such as Products in Product Categories, Employees in Departments.

It's easier in coding to handle the hierarchical relationship this way.

like image 31
DOK Avatar answered Dec 15 '22 10:12

DOK