using System.Collections.Generic;
namespace CodeMatchingExample
public static void Main(string[] args)
List<string> existingCodes = new List<string> { "AB101", "AB102", "AB103" };
Dictionary<string, List<string>> codeLists = new Dictionary<string, List<string>>
{ "List 1", new List<string> { "AB101" } },
{ "List 2", new List<string> { "AB102" } },
{ "List 3", new List<string> { "AB103" } },
{ "List 4", new List<string> { "AB101", "AB102" } },
{ "List 5", new List<string> { "AB101", "AB102", "AB103" } },
{ "List 6", new List<string> { "AB101", "AB102", "AB103","AB104" } },
{ "List 7", new List<string> { "AB101", "AB102", "AB105","AB104" } }
var matchingLists = codeLists.Where(kvp => kvp.Value.All(code => existingCodes.Contains(code)))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
if (matchingLists.Count > 0)
Console.WriteLine("Lists with all codes present:");
foreach (var listName in matchingLists.Keys)
Console.WriteLine(listName);
var maxMatchesList = matchingLists.OrderByDescending(pair => pair.Value.Count).FirstOrDefault();
Console.WriteLine("Exclusive Match: " + maxMatchesList.Key);
Console.WriteLine("No matching list found.");