public partial class Form1 : Form
{
public Form1( )
{
InitializeComponent( ) ;
}
public Control AddControl( Control c)
{
this.Controls .Add ( c) ;
return c;
}
public Control CreateControl( )
{
return new Control( ) ;
}
private void button1_Click( object sender, EventArgs e)
{
var list = new List< int> ( ) { 1 , 2 , 3 , 4 , 5 } ;
var list2 = list.Select ( ( v) => this.CreateControl ( ) ) ;
list2.ForEach ( ( v) => this.AddControl ( v) ) ;
list2.ForEach ( ( v) => Console.WriteLine ( v.Parent .Name ) ) ;
}
private void button2_Click( object sender, EventArgs e)
{
var list = new List< int> ( ) { 1 , 2 , 3 , 4 , 5 } ;
var list2 = list.Select ( ( v) => this.CreateControl ( ) ) ;
var list3 = list2.Select ( ( v) => this.AddControl ( v) ) ;
list3.ForEach ( ( v) => Console.WriteLine ( v.Parent .Name ) ) ;
}
}
public static class LinqExtension
{
public static void ForEach< T> ( this IEnumerable< T> arr, Action< T> pred)
{
foreach ( var v in arr) { pred( v) ; }
}
}
cHVibGljIHBhcnRpYWwgY2xhc3MgRm9ybTEgOiBGb3JtCiAgICB7CiAgICAgICAgcHVibGljIEZvcm0xKCkKICAgICAgICB7CiAgICAgICAgICAgIEluaXRpYWxpemVDb21wb25lbnQoKTsKCgogICAgICAgIH0KCiAgICAgICAgcHVibGljIENvbnRyb2wgQWRkQ29udHJvbChDb250cm9sIGMpCiAgICAgICAgewogICAgICAgICAgICB0aGlzLkNvbnRyb2xzLkFkZChjKTsKICAgICAgICAgICAgcmV0dXJuIGM7CiAgICAgICAgfQogICAgICAgIHB1YmxpYyBDb250cm9sIENyZWF0ZUNvbnRyb2woKQogICAgICAgIHsKICAgICAgICAgICAgcmV0dXJuIG5ldyBDb250cm9sKCk7CiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgYnV0dG9uMV9DbGljayhvYmplY3Qgc2VuZGVyLCBFdmVudEFyZ3MgZSkKICAgICAgICB7CiAgICAgICAgICAgIHZhciBsaXN0ID0gbmV3IExpc3Q8aW50PigpIHsgMSwyLDMsNCw1IH07CgogICAgICAgICAgICB2YXIgbGlzdDIgPSBsaXN0LlNlbGVjdCgodikgPT4gdGhpcy5DcmVhdGVDb250cm9sKCkpOwogICAgICAgICAgICBsaXN0Mi5Gb3JFYWNoKCh2KSA9PiB0aGlzLkFkZENvbnRyb2wodikpOwogICAgICAgICAgICBsaXN0Mi5Gb3JFYWNoKCh2KSA9PiBDb25zb2xlLldyaXRlTGluZSh2LlBhcmVudC5OYW1lKSk7CiAgICAgICAgfQoKICAgICAgICBwcml2YXRlIHZvaWQgYnV0dG9uMl9DbGljayhvYmplY3Qgc2VuZGVyLCBFdmVudEFyZ3MgZSkKICAgICAgICB7CgogICAgICAgICAgICB2YXIgbGlzdCA9IG5ldyBMaXN0PGludD4oKSB7IDEsIDIsIDMsIDQsIDUgfTsKCiAgICAgICAgICAgIHZhciBsaXN0MiA9IGxpc3QuU2VsZWN0KCh2KSA9PiB0aGlzLkNyZWF0ZUNvbnRyb2woKSk7CiAgICAgICAgICAgIHZhciBsaXN0MyA9IGxpc3QyLlNlbGVjdCgodikgPT4gdGhpcy5BZGRDb250cm9sKHYpKTsKICAgICAgICAgICAgbGlzdDMuRm9yRWFjaCgodikgPT4gQ29uc29sZS5Xcml0ZUxpbmUodi5QYXJlbnQuTmFtZSkpOwogICAgICAgIH0KICAgICAgICAKICAgIH0KICAgIHB1YmxpYyBzdGF0aWMgY2xhc3MgTGlucUV4dGVuc2lvbgogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBGb3JFYWNoPFQ+KHRoaXMgSUVudW1lcmFibGU8VD4gYXJyLCBBY3Rpb248VD4gcHJlZCkKICAgICAgICB7CiAgICAgICAgICAgIGZvcmVhY2ggKHZhciB2IGluIGFycikgeyBwcmVkKHYpOyB9CiAgICAgICAgfQogICAgfQ==
compilation info
prog.cs(1,30): error CS0246: The type or namespace name `Form' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout