What’s the easiest way to remove every element after and including the nth element in a System.Collections.Generic.List<T>?
What’s the easiest way to remove every element after and including the nth element
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you can use
RemoveRangemethod, simply do: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:
Conversely, you can use:
But that will create a new list, which may not be what you want.