fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class ErrorLog
  6. {
  7. public int Line { get; set; }
  8. public string Message { get; set; }
  9.  
  10. public ErrorLog(int line, string message)
  11. {
  12. this.Line = line;
  13. this.Message = message;
  14. }
  15. }
  16.  
  17. class Logger
  18. {
  19. public static void Write(IEnumerable<ErrorLog> logs)
  20. {
  21. string output = string.Join("\n", logs.GroupBy(x => x.Line)
  22. .Select(x => x.Key + "行目:" + string.Join("\n", x.Select(y => y.Message))));
  23.  
  24. Console.WriteLine(output);
  25. }
  26. }
  27.  
  28. public class Test
  29. {
  30. public static void Main()
  31. {
  32. var logs = new[]
  33. {
  34. new ErrorLog(3, "名前の値が不正です"),
  35. new ErrorLog(3, "性別の値が不正です"),
  36. new ErrorLog(3, "生年月日が不正です"),
  37. new ErrorLog(4, "性別の値が不正です"),
  38. };
  39. Logger.Write(logs);
  40. }
  41. }
Success #stdin #stdout 0.05s 24136KB
stdin
Standard input is empty
stdout
3行目:名前の値が不正です
性別の値が不正です
生年月日が不正です
4行目:性別の値が不正です