Hello, I've recently been bitten by the (way too commmon in my opinion) gotcha of Concat
returns it's result, rather than appending to the list itself.
For instance.
List<Control> mylist=new List<Control>;
//.... after adding Controls into mylist
MyPanel.Controls.Concat(mylist); //This will not affect MyPanel.Controls at all.
MyPanel.Controls=MyPanel.Controls.Concat(mylist); //This is what is needed, but the Controls reference can not be reassigned (for good reason)
So is there some other way of combining two lists that will work when the collection reference is read-only?
Is the only way to do this with a foreach?
foreach(var item in mylist){
MyPanel.Controls.Add(item);
}
Is there a better way without the foreach?