fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class SettingsEntry
  6. {
  7. public string Name{get; set; }
  8. public object Value {get; set; }
  9. }
  10.  
  11. public class Settings : List<SettingsEntry>
  12. {
  13. public object this[string name]
  14. {
  15. get { return this.SingleOrDefault((entry) => entry.Name.Equals(name))?.Value; }
  16. }
  17. }
  18.  
  19. public class Test
  20. {
  21. public static void Main()
  22. {
  23. Settings settings = new Settings()
  24. {
  25. new SettingsEntry()
  26. {
  27. Name = "ServiceUrl",
  28. Value = "http://myhost/myservice.asmx"
  29. },
  30. new SettingsEntry()
  31. {
  32. Name = "ServiceTimeout",
  33. Value = 10000
  34. }
  35. };
  36.  
  37. Console.WriteLine(settings["ServiceUrl"]);
  38. Console.WriteLine(settings["ServiceTimeout"]);
  39. Console.WriteLine(settings["Bla"]);
  40. }
  41. }
Success #stdin #stdout 0.02s 15604KB
stdin
Standard input is empty
stdout
http://myhost/myservice.asmx
10000