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

I have a WCF service that I cannot touch that returns List<FilesWithSettings>. I need to enter several PCs that are grouped together and retrieve List<FilesWithSettings>for each of them along with PCIdentifier, which leads me to Dictionary<PCIdentifier,List<FilesWithSettings>>or List<PCIdentifier>and List<List<FilesWithSettings>>which are not elegant and unreadable.

Can you give me a more elegant solution?

+5
source share
3 answers

I think you have three options:

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

or

Dictionary<PCIdentifier, List<T>>

Which says better about your intentions 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 also good.

+6
source

I would have something like

[DataContract]
public class PCState // need a better name
{
    [DataMember]
    public PCIdentifier Identifier {get;set;}
    [DataMember]
    public List<FilesWithSettings> Files {get;set;}
}

a List<PCState>. .., .

+5

Dictionary<PCIdentifier,List<FilesWithSettings>>actually quite elegant. You can clearly identify individual PCs and iterate over all PCs, as well as receive all the data needed for each PC.

+2
source

All Articles