Select all items from one collection to another collection of same type

Public class xyz: ICloneable
{
// Properties

public object Clone()
{
return this.MemberwiseClone();
}
}


public class xyzCol : List<xyz>
{
}

private xyzCol xyzCol1= new xyzCol();
private xyzCol xyzCol2= new xyzCol();

xyzCol1= // Get data from service.

Now select all items from xyzCol1 into xyzCol2. (Not assgning xyzCol1 to xyzCol2)

xyzCol2.Clear();
xyzCol1.ForEach(i => xyzCol2.Add(i.Clone() as xyzCol));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s