How to truncate a list?

If you can use RemoveRange method, simply do:

list.RemoveRange(index, count);

Where index is where to start from and count is how much to remove. So to remove everything from a certain index to the end, the code will be:

list.RemoveRange(index, list.Count - index);

Conversely, you can use:

list.GetRange(index, count);

But that will create a new list, which may not be what you want.

Leave a Comment