fork download
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. Dictionary<string, int> paths = new Dictionary<string, int>();
  11. paths.Add("/abc/12", 1);
  12. paths.Add("/test/abc", 2);
  13. paths.Add("/stack/overflow/com", 3);
  14. paths.Add("/stack/exception", 3);
  15.  
  16. List<string> filter = new List<string>();
  17. filter.Add("/abc");
  18. filter.Add("/stack/overflow");
  19.  
  20. var toDelete = paths
  21. .Where(kv => !filter.Any(f => kv.Key.StartsWith(f)));
  22. foreach (var delete in toDelete.Reverse())
  23. paths.Remove(delete.Key);
  24.  
  25. foreach(var kv in paths)Console.WriteLine("{0} {1}",kv.Key,kv.Value);
  26. }
  27. }
Success #stdin #stdout 0.07s 34096KB
stdin
Standard input is empty
stdout
/abc/12 1
/stack/overflow/com 3