Remove oldest n Items from List using C#

Use List<T>.RemoveRange – something like this:

// number to remove is the difference between the current length
// and the maximum length you want to allow.
var count = scoreList.Count - (Items.Count() * 3);
if (count > 0) {
    // remove that number of items from the start of the list
    scoreList.RemoveRange(0, count);
}

You remove from the start of the list, because when you Add items they go to the end – so the oldest are at the start.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)