using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
public enum AllowedOutOfStockOrderMode
public static void Main()
var productAllowedModes = new Dictionary<string, HashSet<AllowedOutOfStockOrderMode>>();
var productAllowedOutOfStockOrderModes = "R9-165|1,;";
foreach (var record in productAllowedOutOfStockOrderModes.Split(';'))
var productModes = record.Split('|');
var oosModes = new HashSet<AllowedOutOfStockOrderMode>();
if (productModes == null || productModes.Length < 2 || productModes[0] == null || productModes[1] == null)
Console.WriteLine(productModes);
Console.WriteLine(productModes);
Console.WriteLine("Skip this");
foreach (var oos in productModes[1].Split(',', StringSplitOptions.RemoveEmptyEntries))
oosModes.Add((AllowedOutOfStockOrderMode)Int32.Parse(oos));
if (productAllowedModes.TryGetValue(productModes[0], out var oosModesExisting))
oosModes = oosModes.Concat(oosModesExisting).ToHashSet();
productAllowedModes[productModes[0]] = oosModes;
productAllowedModes.Add(productModes[0], oosModes);
var s = productAllowedModes.ToImmutableDictionary(
x => x.Value.ToImmutableHashSet()
Console.WriteLine("=========");
Console.WriteLine(rec.Key);
Console.WriteLine(String.Join(",", rec.Value));