views:

93

answers:

3

I want a dictionary containing the names and text of all controls. Is it possible with predefined framework methods/LINQ/colection initializers or do I have to make a loop and add all entries by myself?

This gives me an error message:

List<Control> controls;
// .. initialize list ..
controls.ToDictionary((Control child,string k)=>new KeyValuePair<string,string>(child.Name, child.Text));
+3  A: 

The call should be like this:

controls.ToDictionary(
    c => c.Name,       // Key selector
    c => c.Text);      // Element selector.
Ronald Wildenberg
+2  A: 

It should probably look something like this:

controls.ToDictionary(c => c.Name, c => c.Text);
LukeH
+1  A: 
Dictionary<String, String> myControls = ((from Control c in Controls select c).ToDictionary(c => c.Name, c => c.Text))
Asher