Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid using List<List<T>>?

Tags:

c#

I have a WCF service that i cannot touch which returns List<FilesWithSettings>. I need to enter few PC which are grouped together and retrieve List<FilesWithSettings> for each one along with PCIdentifier which brings me to Dictionary<PCIdentifier,List<FilesWithSettings>> or List<PCIdentifier> and List<List<FilesWithSettings>> which isn't elegant and unreadable.

Can you give me more elegant solution ?

like image 639
eugeneK Avatar asked Dec 08 '11 07:12

eugeneK


People also ask

How do I stop using a to-do list?

One of my inspirations to stop using a to-do list is Peter Drucker, the author of The Effective Executive. When I get too busy with things that I shouldn’t be doing, I remind myself of his classic quote: “There is nothing so useless as doing efficiently that which should not be done at all.”

Should you throw out your to-do lists?

So if you’re regularly getting overwhelmed with your to-do lists, consider throwing them out. Or, see it as a wake-up call to rethink your work. Most of us can work without a list. I can see why people used the to-do list a hundred years ago. It was their best alternative.

Is the to-do list really necessary?

“There is nothing so useless as doing efficiently that which should not be done at all.” T he to-do list is one of the most widely used productivity tactics. For years, I also had a list of dozens of items. When I started researching productivity, I thought the to-do list was a must. “Everyone uses them, so it must work!”

How can I combine two lists into one list?

You could use a simple Union + Distinct: That will add all the items from the second list into the first list, and then return all the unique strings in the combined list. Not likely to perform well with large lists, but it's simple.


Video Answer


1 Answers

I guess you've got three options:

List<List<T>> // Which is pretty nasty

or:

Dictionary<PCIdentifier, List<T>>

Which better enunciates your intent or even:

class PCResult
{
    PCIdentifier Identifier { get; set; };
    List<T> Results { get; set; }
}

and

List<PCResult>

Personally I prefer the third, but the second is fine too.

like image 71
Jackson Pope Avatar answered Oct 17 '22 02:10

Jackson Pope