using System.Collections.Generic;
public static void Main()
List<int> userIds = new List<int>
List<Fubar> widgets = new List<Fubar>();
widgets.Add(new Fubar { Id = 1, Name = "Tom" });
widgets.Add(new Fubar { Id = 2, Name = "Dick" });
widgets.Add(new Fubar { Id = 3, Name = "Harry" });
List<int> widgetIds = widgets.Select(x => x.Id).ToList();
Console.WriteLine("compare widgets to userIds" );
Console.WriteLine("Get matches");
List<int> matches = widgetIds.Intersect(userIds).ToList();
Console.WriteLine(string.Join(";", matches));
Console.WriteLine("Do we have any entries in widgets that do not exist in userIds ?" );
Console.WriteLine("if yes then add them" );
List<int> widgetsNotInUserIds = widgetIds.Except(userIds).ToList();
Console.WriteLine(string.Join(";", widgetsNotInUserIds));
Console.WriteLine("Do we have any entries in userIds that do not exist in widgets?" );
Console.WriteLine("if yes then delete them");
List<int> userIdsNotInWidgets = userIds.Except(widgetIds).ToList();
Console.WriteLine(string.Join(";", userIdsNotInWidgets));
public int Id { get; set; }
public string Name { get; set; }