serkan sendur 821 Postaholic Banned Featured Poster

When working with reference types, sometimes you want to add some items to one list which has been assigned another list by reference. When you add new items to your new list, the previous list also gets added the new items since they refer to the same object collection in the memory. For these cases we clone the objects before assigning them to the others. Although DataTable class has a clone method, generic list has not. The following is a way to clone generic lists.

List<myEntityClass> li = new List<myEntityClass>((myEntityClass[])myEntityClassList.ToArray().Clone());

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.