score:12

Accepted answer

Try this:

NewItems.AddRange(OldItems.Take(10));
OldItems = OldItems.Skip(10).ToList();

alternate:

NewItems.AddRange(OldItems.Take(10));
OldItems.RemoveRange(0,10);

Take will take x first items from your list look here. Skip will skip x elements from your list look here. RemoveRange is an alternative option if you will use lists reference.

As Matthew said second option won't create new list and do removal in-place, so it's prefered.

score:3

You could do:

var NewItems = OldItems.GetRange(0, 10);
OldItems.RemoveRange(0, 10);

(this doesn't use Linq)

score:1

You can use the

GetRange(int index, int count); RemoveRange(int index, int count);

To implement this.

score:2

Try this

List<Item> oldItems = new List<Item>();
List<Item> newItems = new List<Item>();
newItems.AddRange(oldItems.Take(10));//add first 10 items to new list
oldItems.RemoveRange(0, 10);//remove first 10 items from old list

score:-2

List<string> checkForNull = new List<string>();
        List<string> newList = new List<string>();
        for (int i = 0; i < 10; i++)
        {
            checkForNull.Add(Convert.ToString(i));
        }
        for (int i = 10; i < 20; i++)
        {
            newList.Add(Convert.ToString(i));
        }
        checkForNull.AddRange(newList.Take(5));
        newList.RemoveRange(0, 5);

Related Articles