Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# What is the best way to copy a BindingList?

Tags:

c#

bindinglist

What is the best way to copy a BindingList?

Just use ForEach()? Or are there better ways?

like image 310
Martijn Avatar asked Sep 16 '25 04:09

Martijn


1 Answers

BindingList has a constructor which can take an IList. And BindingList implements IList. So you can just do the following:

BindingList newBL = new BindingList(oldBL);

Of course that creates a second list that just points at the same objects. If you actually want to clone the objects in the list then you have to do more work.

like image 53
RationalGeek Avatar answered Sep 17 '25 18:09

RationalGeek