Does the list of lists smell bad, what are my other options

I need to put together a list of lists, but the whole idea does not look too pretty. It just sounds so bulky. is there any other template for storing a list of lists.

my first one though is to use an array of List from Arraylist.

C # ,. net-2

more: then the number of elements that need to be kept is small, but it always changes.

Note: I have been fixed regarding the use of ArrayLists on this issue:

What is wrong with using ArrayList in .net-2.0

+4
source share
6 answers

There is nothing wrong with List<List<T>> - LINQ SelectMany can be your friend in this situation.

+6
source

How to use objects created in custom classes?

For example, clients may have multiple addresses. Create a Customer object that has the Address property. Then you can have a collection (array, ArrayList, etc.) of Clients, and each Client can have a collection of Addresses.

This is suitable for many types of information, such as products in product categories, employees in departments.

It is easier to code to handle hierarchical relationships this way.

+2
source

you can, but it's better to wrap it in a class with well-defined public methods.

+2
source

Not a problem at all. I already used it, and it was suitable for what I needed at that time. A template is a list of lists. :)

+1
source

A list of lists per se is not a bad smell. If your lists will be the same size, you can use a 2D array, for example. int[2,2] , but if the lists have different lengths, then the list of lists is the correct way, except for the formal coding of the class for a dangling 2D array.

+1
source

You can, of course, do this using either generic lists or using a non-generic ArrayList variant.

 List<List<string>> listOfLists = new List<List<string>>(); listOfLists.Add(new List<string>()); listOfLists.Add(new List<string>()); ArrayList stringListOfStringLists = new ArrayList(); stringListOfStringLists.Add(new ArrayList()); stringListOfStringLists.Add(new ArrayList()); 
+1
source

All Articles