fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp1
  5. {
  6. public class Question
  7. {
  8. public Question(string p1, string p2, string p3, string p4, string a)
  9. {
  10. prompt1 = p1;
  11. prompt2 = p2;
  12. prompt3 = p3;
  13. prompt4 = p4;
  14. answer = a;
  15. }
  16.  
  17. public override string ToString()
  18. {
  19. return "a) " + prompt1 + "\nb) " + prompt2 + "\nc) " + prompt3 + "\nd) " + prompt4 + "\n" + answer + "\n";
  20. }
  21.  
  22. private string prompt1;
  23. private string prompt2;
  24. private string prompt3;
  25. private string prompt4;
  26. private string answer;
  27. }
  28.  
  29. class Program
  30. {
  31. static void Main(string[] args)
  32. {
  33. List<Question> l = new List<Question>();
  34. l.Add(new Question("q1prompt1", "q1prompt2", "q1prompt3", "q1prompt4", "q1answer"));
  35. l.Add(new Question("q2prompt1", "q2prompt2", "q2prompt3", "q2prompt4", "q2answer"));
  36. l.Add(new Question("q3prompt1", "q3prompt2", "q3prompt3", "q3prompt4", "q3answer"));
  37. l.Add(new Question("q4prompt1", "q4prompt2", "q4prompt3", "q4prompt4", "q4answer"));
  38. l.Add(new Question("q5prompt1", "q5prompt2", "q5prompt3", "q5prompt4", "q5answer"));
  39. l.Add(new Question("q6prompt1", "q6prompt2", "q6prompt3", "q6prompt4", "q6answer"));
  40.  
  41.  
  42. PrintList(l);
  43. Console.WriteLine();
  44. Shuffle(l);
  45. PrintList(l);
  46. Console.WriteLine();
  47. }
  48.  
  49. private static Random rng = new Random();
  50.  
  51. public static void Shuffle<T>(IList<T> list)
  52. {
  53. int n = list.Count;
  54. while (n > 1)
  55. {
  56. n--;
  57. int k = rng.Next(n + 1);
  58. T value = list[k];
  59. list[k] = list[n];
  60. list[n] = value;
  61. }
  62. }
  63.  
  64. public static void PrintList<T>(IList<T> list)
  65. {
  66. foreach(T el in list)
  67. {
  68. Console.WriteLine(el.ToString());
  69. }
  70. }
  71. }
  72. }
  73.  
Success #stdin #stdout 0.02s 14824KB
stdin
Standard input is empty
stdout
a) q1prompt1
b) q1prompt2
c) q1prompt3
d) q1prompt4
q1answer

a) q2prompt1
b) q2prompt2
c) q2prompt3
d) q2prompt4
q2answer

a) q3prompt1
b) q3prompt2
c) q3prompt3
d) q3prompt4
q3answer

a) q4prompt1
b) q4prompt2
c) q4prompt3
d) q4prompt4
q4answer

a) q5prompt1
b) q5prompt2
c) q5prompt3
d) q5prompt4
q5answer

a) q6prompt1
b) q6prompt2
c) q6prompt3
d) q6prompt4
q6answer


a) q4prompt1
b) q4prompt2
c) q4prompt3
d) q4prompt4
q4answer

a) q1prompt1
b) q1prompt2
c) q1prompt3
d) q1prompt4
q1answer

a) q5prompt1
b) q5prompt2
c) q5prompt3
d) q5prompt4
q5answer

a) q3prompt1
b) q3prompt2
c) q3prompt3
d) q3prompt4
q3answer

a) q2prompt1
b) q2prompt2
c) q2prompt3
d) q2prompt4
q2answer

a) q6prompt1
b) q6prompt2
c) q6prompt3
d) q6prompt4
q6answer