Remove confusion

Jun 2, 2014 at 1:53 PM
It is confusing, the list remove items and need reassign.
Is it good to change to something like this?
Link
var c = new ObservableCollection<SelectableItem>();
c.Remove(x => x.IsSelected);
original code:
List<int> TestObject = new int[] { 1, 2, 3, 4, 5, 6 }.ToList();
            TestObject = TestObject.Remove((x) => x % 2 == 0).ToList();
            Assert.Equal(3, TestObject.Count());
            foreach (int Item in TestObject)
                Assert.False(Item % 2 == 0);
Coordinator
Jun 2, 2014 at 5:34 PM
The remove function is a generic extension method on IEnumerable<T>. No way to really do what you are suggesting on that level.
Coordinator
Jun 3, 2014 at 12:37 AM
Finally had a chance to think about the issue. Basically the remove extension method, since it is at the IEnumerable<T> level, can't directly remove from the list and leave it in place. So it probably makes more sense to rename the Remove extension to something like WhereNot(). It's basically a negated where clause. I just need to figure out a better name so that it's easy to find and not confusing as to the intent. I'm going to leave the 3.4.X version the same so that I don't screw up too many people's code but I'll make the change in the 4.0 version.
Jun 3, 2014 at 2:05 AM
JaCraig wrote:
Finally had a chance to think about the issue. Basically the remove extension method, since it is at the IEnumerable<T> level, can't directly remove from the list and leave it in place. So it probably makes more sense to rename the Remove extension to something like WhereNot(). It's basically a negated where clause. I just need to figure out a better name so that it's easy to find and not confusing as to the intent. I'm going to leave the 3.4.X version the same so that I don't screw up too many people's code but I'll make the change in the 4.0 version.
Nice to hear that. Thanks you.
Coordinator
Jun 5, 2014 at 2:03 PM
Also, in case you're curious, I went with Except as the name in 4.0. Makes it simple to find since that's a Linq extension already that acts in a similar manner and should be a bit easier to figure out what it's doing.