I have code that looks like this:
class A {
public string Name {get;set;}
public IList<string> Keywords {get;set;}
}
…
IList<A> a = new List<A>{
new A{Name = "a1", Keywords = new List<string>{"k1", "k2"}},
new A{Name = "a2", Keywords = new List<string>{"k1", "k3"}},
new A{Name = "a3", Keywords = new List<string>{"k3", "k4"}},
new A{Name = "a4", Keywords = new List<string>{"k1", "k3", "k4"}}
};
Is there any way I can use LINQ to create a dictionary in the form of:
{"k1", List<A> {a1, a2, a4}}
{"k2", List<A> {a1}}
{"k3", List<A> {a2, a3, a4}}
{"k4", List<A> {a3, a4}}
Basically mapping the objects to the keywords.
Thanks
Something like
should do it.