you can replace the whole removal loop with this line,
Code:numbers.RemoveAll(item => item == 1);
Wow good one!
Edited: yes this is one way to fix it.for (var i= numbers.Count-1; i>=0; i--) {
}
Last edited:
you can replace the whole removal loop with this line,
Code:numbers.RemoveAll(item => item == 1);
Edited: yes this is one way to fix it.for (var i= numbers.Count-1; i>=0; i--) {
}
for (int i = 0; i < numbers.Count; i++)
{
if (numbers[i] == 1)
numbers.Remove(numbers[i--]);
}
int i = 0;
while (i < numbers.Count)
{
if (numbers[i] == 1)
numbers.Remove(numbers[i]);
else
i++;
}
loops නැතුව මේ විදියටත් ගන්න පුලුවන්@NEMISIS @hasithayad හරි උත්තර දීලා තියෙනවා.
අකුරු දෙකක ෆික්ස් එකක් කියන්නේ එලිමන්ට් එක රිමූව් කලාම i-- කරන එක.
C#:for (int i = 0; i < numbers.Count; i++) { if (numbers[i] == 1) numbers.Remove(numbers[i--]); }
මේක ලියන්න පුලුවන් එක විදියක්
C#:int i = 0; while (i < numbers.Count) { if (numbers[i] == 1) numbers.Remove(numbers[i]); else i++; }
And thanks everyone who replied
numbers = numbers.Where(x => x != 1).ToList();
numbers = (from x in numbers where x != 1 select x).ToList<int>();
I think you can also use ElementOrDefault as well
I meant to fix a possible NRE, but yeah logic bug won't be fixed by that. I missed foreach vs. for loop. Good catch.Can you post your code using that method?
I meant to fix a possible NRE, but yeah logic bug won't be fixed by that. I missed foreach vs. for loop. Good catch.
code security balanne automation walinda oyala?ප්රශ්නේ ගොන්ද නැත්නම් මම ගොන්ද කියලා හිතාගන්න බෑ
ඔව්.code security balanne automation walinda oyala?