fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7. class x
  8. {
  9. public int QuestionID;
  10. }
  11. class objx
  12. {
  13. public int RowNumber;
  14. public int DatabaseID;
  15. public int SetID;
  16. }
  17.  
  18. public static void Main()
  19. {
  20. var objY = new List<x>() {
  21. new x{QuestionID=1}, new x{QuestionID=2}, new x{QuestionID=3},
  22. new x{QuestionID=4}, new x{QuestionID=5}, new x{QuestionID=6},
  23. new x{QuestionID=7}, new x{QuestionID=8}, new x{QuestionID=9},
  24. new x{QuestionID=1}, new x{QuestionID=2}, new x{QuestionID=3},
  25. new x{QuestionID=4}, new x{QuestionID=5}, new x{QuestionID=6},
  26. new x{QuestionID=7}, new x{QuestionID=8}, new x{QuestionID=9},
  27. new x{QuestionID=1}, new x{QuestionID=2}, new x{QuestionID=3},
  28. new x{QuestionID=4}, new x{QuestionID=5}, new x{QuestionID=6},
  29. new x{QuestionID=7}, new x{QuestionID=8}, new x{QuestionID=9}
  30. };
  31. var objX = objY.Select((x, i) => new { ObjX = x, Index = i })
  32. .GroupBy(x => x.Index / 5)
  33. .Select((g, i) =>
  34. g.Select(x => new objx
  35. {
  36. RowNumber = x.Index + 1,
  37. DatabaseID = x.ObjX.QuestionID,
  38. SetID = i + 1
  39. }).ToList())
  40. .ToList();
  41.  
  42. foreach(var xList in objX)
  43. Console.WriteLine("Count: " + xList.Count);
  44. }
  45. }
Success #stdin #stdout 0.06s 35144KB
stdin
Standard input is empty
stdout
Count: 5
Count: 5
Count: 5
Count: 5
Count: 5
Count: 2