using System.Collections.Generic;
public class ExternalIdInformation
public string ProductId {get;set;}
public static class Extensions
public static IEnumerable<TSource> DistinctBy<TSource, TKey>
(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
if (seenKeys.Add(keySelector(element)))
public static void Main()
List<ExternalIdInformation> modifiedCatalogItems = new List<ExternalIdInformation>();
List<ExternalIdInformation> changedInventoryItems = new List<ExternalIdInformation>();
modifiedCatalogItems.Add(new ExternalIdInformation {ProductId = "1"});
modifiedCatalogItems.Add(new ExternalIdInformation {ProductId = "2"});
modifiedCatalogItems.Add(new ExternalIdInformation {ProductId = ""});
changedInventoryItems.Add(new ExternalIdInformation {ProductId = "1"});
changedInventoryItems.Add(new ExternalIdInformation {ProductId = "2"});
changedInventoryItems.Add(new ExternalIdInformation {ProductId = "3"});
var results = CombineLists(modifiedCatalogItems, changedInventoryItems);
foreach(var result in results)
Console.WriteLine(result.ProductId == "" ? "Emtpty" : result.ProductId);
private static List<ExternalIdInformation> CombineLists(List<ExternalIdInformation> modifiedCatalogItems, List<ExternalIdInformation> changedInventoryItems)
IEnumerable<ExternalIdInformation> modifiedNonProducts = modifiedCatalogItems
.Where(p => string.IsNullOrEmpty(p.ProductId));
IEnumerable<ExternalIdInformation> modifiedProducts = modifiedCatalogItems
.Where(p => !string.IsNullOrEmpty(p.ProductId))
.Union(changedInventoryItems)
.DistinctBy(p => p.ProductId);
return modifiedNonProducts.Union(modifiedProducts).ToList();