how to Remove list items for my collection

Posted by Jayakumars under ASP.NET AJAX on 4/16/2012 | Points: 10 | Views : 2151 | Status : [Member] [MVP] | Replies : 2
Hi

i have list items 10
here how to remove my listitems after 5 how will do this

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com



Responses

Posted by: Gow.Net on: 4/16/2012 [Member] Starter | Points: 25

Up
0
Down
apply RemoveAt method
 List<string> s = new List<string>();

s.RemoveRange(5, 10);
s.RemoveAt(5);


gowthaman8870226416

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: dhirenkaunar-15094 on: 4/16/2012 [Member] Starter | Points: 25

Up
0
Down
List<string> s = new List<string>();
s.Add("1");
s.Add("2");
s.Add("3");
s.Add("4");
s.Add("5");
s.Add("6");
s.Add("7");
s.Add("8");
s.Add("9");
s.Add("10");
s.RemoveRange(5, 5); // RemoveRange has two inputs input1 specify from stating index and input 2 specify how many elements you want to delete after the given index
i.e if will give s.RemoveRange(5, 5); then list has only 1,2,3,4,5 i.e this will remove 5 elements after five
and if will give s.RemoveRange(5, 2); then list has only 1,2,3,4,5,8,9,10 i.e this will remove 2 elements after five
The below code will resolve you issue dynamically
s.RemoveRange(5, s.Count-5);


Thanks & Rgards,
Dhiren Kumar Kaunar

Jayakumars, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response