How to remove elements from an array

前端 未结 5 1161
闹比i
闹比i 2021-01-15 08:22

Hi I\'m working on some legacy code that goes something along the lines of

for(int i = results.Count-1; i >= 0; i--)
{
  if(someCondition)
  {
     result         


        
5条回答
  •  余生分开走
    2021-01-15 09:09

    It doesn't seem like the Remove should work at all. The IList implementation should fail if we're dealing with a fixed-size array, see here.

    That being said, if you're dealing with a resizable list (e.g. List), why call Remove instead of RemoveAt? Since you're already navigating the indices in reverse, you don't need to "re-find" the item.

提交回复
热议问题