Foreach
returns void
that is why you are getting the error. Your statement on the right hand side of assignment is not returning anything. You can do the same in two statements like:
var v = new List<Form1>() { this };
v.ForEach(x => { x.GetType().Name.Contains(typeof(Button).Name); });
In your current code you are creating a new List<Form1>
and then iterating over each item in the list, but you are not returning anything.
As Jon Skeet has pointed out in the comment, it will not have any effect on the list. I guess you are trying to get all the button from your list of forms you can do:
var allButtons = v.SelectMany(r => r.Controls.OfType<Button>()).ToList();
v
, not on the constructed object, as ForEach returns void and you are then trying to assign void to the variable – Geoponic