fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var dict = new Dictionary<string, string>()
  10. {
  11. {"question1", "7"},
  12. {"question1_comment", "pretty difficult"},
  13. {"question2", "9"},
  14. {"question2_comment", ""},
  15. {"question3", "5"},
  16. {"question3_comment", "Never on time"},
  17. };
  18.  
  19.  
  20. var list = dict
  21. .Where(x => !x.Key.Contains("comment"))
  22. .Select(x =>
  23. new Question()
  24. {
  25. QuestionId =x.Key,
  26. Answer = x.Value,
  27. Comment = dict.Single(y => y.Key == String.Concat(x.Key,"_comment")).Value
  28. })
  29. .ToList();
  30.  
  31. foreach (var item in list)
  32. Console.WriteLine(String.Format("{0} - {1} - {2}", item.QuestionId, item.Answer, item.Comment));
  33. }
  34. }
  35.  
  36. public struct Question
  37. {
  38. public string QuestionId { get; set; }
  39. public string Answer { get; set; }
  40. public string Comment { get; set; }
  41. }
  42.  
Success #stdin #stdout 0.05s 24096KB
stdin
Standard input is empty
stdout
question1 - 7 - pretty difficult
question2 - 9 - 
question3 - 5 - Never on time