C# – Make a List of Lists where List Has Different Type Objects

csilverlight

In ASP.NET 3.5 / Silverlight, I have a situation where I need to send four small Lists from the server to the client. Each sublist is a list of objects. I would like to do this with one call from the client.

So, for example:

ListA is a List of POHeader objects
ListB is a List of POLine objects
ListC is a List of Vendor objects
ListD is a List of Project objects

ListX would be a List containing each of the four lists.

Each of these objects has a different structure. When the List gets back to the client, I'll take it apart and bind each of the four sublists to the relevant control.

Is this possible in C#. I've seen examples of lists of list, but each of the sublists was the same type.

Many thanks
Mike Thomas

Best Answer

Since you always have 4 lists, just make a custom class to hold them, and pass that back:

class POCollection
{
     IList<POHeader> Headers { get; private set; }
     IList<POLine> Lines { get; private set; }
     // etc...
}
Related Topic