skij
asked on
ASP.NET / C# / LINQ: Remove items from list without creating a new list
I would like to remove all numbers that are less than or equal to 3.
This can be done by creating a NEW list and adding the matching numbers to the new list like this:
This produces an error:
Cannot implicitly convert type 'System.Collections.Generi c.IEnumera ble<double >' to 'System.Collections.Generi c.List<dou ble>'.
This can be done by creating a NEW list and adding the matching numbers to the new list like this:
var numbers = new List<double> {-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
var numbers2 = numbers.Where(number => number > 3);
Is it possible to do this using LINQ without creating a new list?This produces an error:
var numbers = new List<double> {-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
numbers = numbers.Where(number => number > 3);
The error is:Cannot implicitly convert type 'System.Collections.Generi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window