I have two general lists, one called “Favorite” and the other “Filtered”.
List<Content> Featured = new List<Content>(); List<Content> Filtered = new List<Content>();
Both contain Content elements, which are simple classes:
public class Content { public long ContentID { get; set;} public string Title { get; set; } public string Url { get; set; } public string Image { get; set; } public string Teaser { get; set; } public Content(long contentId, string title, string url, string image, string teaser) { ContentID = contentId; Title = title; Url = url; Image = image; } }
Any items displayed in Filtered but also displayed in Favorites should be removed from Filtered. In addition, both lists will be merged into one general list with the "Favorites" items that appear first.
I know that I could write a couple of foreach loops to do this, but I cannot help but feel that there should be a more elegant method using LINQ.
I am using C # 4.0.
source share