public MCQ() { InitializeComponent(); Questions = QuestionCollection.GetQuestions().Where(x => x.grade.Equals("Five")).SelectMany(x => x.subjects).Where(x => x.subject.Equals("Science")).SelectMany(x => x.questions).Where(x => x.Qno != 0).ToList(); Total = Questions.Count; ClickAnswer = new int[Total]; Answer = new int[Total]; tClick = new int[tQuestion]; Random rnd = new Random(); Attempt.Content = 0.ToString(); Remaining.Content = tQuestion.ToString(); while (RndQuestion.Count < tQuestion) { int qno = rnd.Next(1, Questions.Count); if (!RndQuestion.Contains(qno)) { RndQuestion.Add(qno); } } question = Questions.Where(x => x.Qno == RndQuestion[qno]).FirstOrDefault(); DataContext = question; }