开发者

Getting Dictionary<string,string> from List<Control>

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 K开发者_如何学运维eyValuePair<string,string>(child.Name, child.Text));


The call should be like this:

controls.ToDictionary(
    c => c.Name,       // Key selector
    c => c.Text);      // Element selector.


It should probably look something like this:

controls.ToDictionary(c => c.Name, c => c.Text);


Dictionary<String, String> myControls = ((from Control c in Controls select c).ToDictionary(c => c.Name, c => c.Text))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜