myRule.ToList().RemoveRange(0, count);
Even though it does not give me error, it does not work. What's the other way?
myRule.ToList().RemoveRange(0, count);
Even though it does not give me error, it does not work. What's the other way?
That's because myRule.ToList() doesn't act on the reference myRule.
If myRule is writeable then this should work:
myRule = myRule.ToList().RemoveRange(0, count);
Of course, if it's a readonly, that won't work at all...just trying to figure out a way around that for you...
What do you mean by "it does not work"? The code is removing the items from the List<T>
built by ToList()
- were you expecting it to remove items from the database (or data context)?
If you're just doing that as a single statement, it's pretty pointless - the list will be built, then some items will be removed - but you don't end up with a reference to the list, so you can't do anything with it.
If you could give us more details about what you want to achieve, that would help.
You might be looking for
myRule.Skip(count);
or you might be looking for
myDataContext.Customers.DeleteAllOnSubmit(myRule.Take(count));