score:12
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);
Source: stackoverflow.com
Related Articles
- Move First 10 List Items to Another Item List
- How do I move items from a list to another list in C#?
- Using LINQ to get a list of items where the item contains a part of an item from another list
- Code First EF: While searching database table is it possible to retrieve list of items it has in DataModel?
- Selecting first or default index of list item where property in list matches a property in another list?
- Finding the different items in a list compared to its first item of the list
- Checking if a list's item has a property contained in another list of items
- Use LINQ to move item to top of list
- LINQ query to find if items in a list are contained in another list
- LINQ - Find all items in one list that aren't in another list
- Remove items of list from another lists with criteria
- Find items from a list which exist in another list
- LINQ return items in a List that matches any Names (string) in another list
- Exclude list items that contain values from another list
- Exclude items of one list in another with different object data types, LINQ?
- Use Linq to move item to bottom of list
- Linq - How to select items from a list that contains only items of another list?
- Find all items whose collection property contains items in another list
- Check if a list contains all of another lists items when comparing on one property
- LINQ select List where sub-list contains item from another list
- Get first item in list from linq query
- In C#, how can i determine if a list has any item from another list?
- Linq - Except one list with items in another
- Check if one list contains all items from another list in order
- Why does adding a list to another list, using add range, remove the elements from the first list?
- Using Linq, get all items from list that are in another List<int>
- C# - Merge list items into one item based on some matching values
- How to generate a unique list of items from another list using LINQ in C#
- Adding only new items from one list to another
- Removing a single item from an enumerable source when the items are equal
- Value cannot be null in linq clause
- C# Linq to find a record that matches a condition, if that record is found return all related records
- Prepare Dynamic Lambda Expression with Checking parentproperty null control
- Photon Unity Leaderboard sorting
- Can't build lambda Expression with unknown type of a property
- LINQ: Join 5 or 6 tables and group by one then count groupby data
- Delete List with same property
- Convert 'ArrayList' to 'List<string>' (or 'List<T>') using LINQ
- Entity Framework Conditional Selection
- How do I order a dictionary based off of another dictionary? C#
- Exception in a CRM LINQ query with joins. Attribute in second table doesn't exist
- How to fully simulate the behavior of a SQL Like in Linq-to-Entities
- Returning many-to-many results with LINQ in C# asp.net
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- How to filter empty textboxes with LINQ?
- Build a dynamic where clause over multiple properties
- Entity Framework (4.0) how to exclude a related table
- How to make a simple formula with the current attributes in LINQ Group By?
- Help converting foreach to Linq
- Linq / Entity Framework logic