1

I am trying to compare two strings containing IDs with Razor, but I can't figure out how to do the compare correctly.

I have two list.

List 1 which is a string placed in a cookie, containing all pages from the user's last visit.

List 2 which is a string of all pages from the user's current visit.

What I want is to do a compare of these two strings to see if there is a page ID in List 2, which isn't in List 1. Then that page will be a new page since the last vist.

I have this code.

var pageList = Request.Cookies["pageCookie"].Value;

var allPages = siteroot.Descendants("Event");

var idList = "";

foreach (var node in allPages.Where("Visible"))
{
    idList += node.Id+",";
}

The two lists looks like:

List1: 1525,1585,1595,1600,1605,1610,1885
List2: 1525,1585,1595,1600,1605,1610,1885,1900

Then I would like to check these two strings to see if there is an ID in List 2 which isn't in List 1 like:

if((id in list 2 not in list 1)) {
   output section
}

That would find that ID 1900 is not in List 1.

Morten Hagh
  • 2,055
  • 8
  • 34
  • 66
  • Possible duplicate of [ASP.NET MVC 3 Compare 2 Lists with Model Objects for duplicates](http://stackoverflow.com/questions/10710835/asp-net-mvc-3-compare-2-lists-with-model-objects-for-duplicates) – Dr. Roggia May 15 '17 at 07:24

1 Answers1

1

Try this:

if (list2.Split(',').Except(list1.Split(',')).Any()) {
            //output section
        }
User3250
  • 2,961
  • 5
  • 29
  • 61