London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Using linq on List<>

Vote:
0

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??

 

/David

#78951
Dec 05, 2013 14:18
Vote:
0

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

or

"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

#78956
Edited, Dec 05, 2013 15:33
Vote:
0

Thanx Jeroen!

#78961
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.