I have a collection:
[ A { ‘a’ => ‘1’, ‘b’ => [‘1’, ‘2’]}
B { ‘a’ => ‘2’, ‘b’ => [‘1′,’2′,’3’]} ]
I’m searching for a function to ‘duplicate’ items in this collection to make next result:
[ A1 { ‘a’ => ‘1’, ‘b’ => ‘1’}
A2 { ‘a’ => ‘1’, ‘b’ => ‘2’}
B1 { ‘a’ => ‘2’, ‘b’ => ‘1’}
B2 { ‘a’ => ‘2’, ‘b’ => ‘2’}
B3 { ‘a’ => ‘2’, ‘b’ => ‘3’} ]
How can i achive such result?
Not very clear about your definition of class A/B. I suppose your class looks like:
And prepare the data like:
Using
.SelectManyto flatten the data:Please ignore some bad programming habits in the code(like public fields), and feel free to suggest the coding-style of the last linq query.