Using linq on List<>


This might not be a typical EPiServer question but i'm trying to remove items from a list using Linq but fails.


I have a Comment class with a string property called UserEmail


When someone adds a new comment and it's saved to DDS i send a email to those how has already commented on the same article but i don't want the person making the comment recive a mail. Like this:

List<PageComment> commentList;

commentList = GetComments(pageRef);
commentList = commentList.RemoveAll(x => x.UserEmail == pageComment.UserEmail);

The Linq expression gives this error:

Cannot implicitly convert type 'int' to 'System.Collections.Generic.List<PageComment>'


Why int? I'm dealing with strings here??



Dec 05, 2013 14:18

You could use something like: commentList= commentList.Where(x => x.UserEmail!=pageComment.UserEmail).ToList();


"commentList.RemoveAll(x => x.UserEmail == pageComment.UserEmail);" instead of "commentList = commentList.RemoveAll(x => x.UserEmail == pageComment.UserEmail);"

the int in the error is the number of elements removed from the list

Edited, Dec 05, 2013 15:33

Thanx Jeroen!

Dec 05, 2013 15:53
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.