4

I have the following code

IDictionary<string, IEnumerable<Control>>

I need to convert it to

IDictionary<string, IEnumerable<string>>

using ClientID as the new value.

Does anybody know how to do this in Linq instead iterating through the dictionary?

Thanks

Podge

1
  • To get the ClientID of all the values in the dictionary, something's going to have to iterate over it! Commented Aug 4, 2010 at 8:41

2 Answers 2

6

Something like

IDictionary<string, IEnumerable<Control>> input = ...
IDictionary<string, IEnumerable<string>> output = 
    input.ToDictionary(item => item.Key,
                       item => item.Value.Select(control => control.ClientID)); 
Sign up to request clarification or add additional context in comments.

Comments

4

Without having a compiler by hand, something like this should work...

dictOne
  .ToDictionary(k=>k.Key, v=>v.Value.Select(c=>c.ClientID))

1 Comment

Thanks very much. I couldn't see the wood for the trees. I was thinking I would have to use SelectMany.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.