I have the following list:
List<MyOwnList> mylist = new List<MyOwnList>(); mylist[0].Name = "Name0"; mylist[0].Class = "Class0"; mylist[1].Name = "Name1"; mylist[1].Class = "Class1"; mylist[2].Name = "Name2"; mylist[2].Class = "Class2"; mylist[3].Name = "Name3"; mylist[3].Class = "Class3"; mylist[4].Name = "Name4"; mylist[4].Class = "Class4"; I want to shorten the length or let's say destroy elements from position 3 and 4. I used the following code but it still prints "5" when I do mylist.Count
for(int i=0; i<mylist.Count; i++) { if(i>2) { mylist[i] = null; } } I expect it to print "3" when I do mylist.Count