Abc.NCrafts.App.ViewModels.Questions.Question.ShuffleAnswers C# (CSharp) Method

ShuffleAnswers() public method

public ShuffleAnswers ( ) : void
return void
        public void ShuffleAnswers()
        {
            for (var index = 0; index < Answers.Count - 1; index++)
            {
                var randomIndex = _random.Next(index, Answers.Count);
                var tmp = Answers[index];
                Answers[index] = Answers[randomIndex];
                Answers[randomIndex] = tmp;
            }
        }
    }

Usage Example

        private static Question LoadQuestion(string questionDirectoryPath)
        {
            var question = new Question();

            foreach (var answerFilePath in Directory.GetFiles(questionDirectoryPath, "Answer*.cs"))
            {
                var answerLines = File.ReadLines(answerFilePath).ToList();
                var answer      = new Answer();

                var correctAnswerLine = answerLines.FirstOrDefault(x => x.Contains("[CorrectAnswer"));
                if (correctAnswerLine != null)
                {
                    answer.IsCorrect    = true;
                    question.Difficulty = ParseDifficulty(correctAnswerLine);
                }

                TrimToClass(answerLines);
                LoadHighlightedSectionIndexes(answerLines, answer);

                answer.Text = string.Join(Environment.NewLine, answerLines);

                question.Answers.Add(answer);
            }
            question.ShuffleAnswers();

            question.MarkdownHelpContent = LoadHelpContent(questionDirectoryPath);
            return(question);
        }
All Usage Examples Of Abc.NCrafts.App.ViewModels.Questions.Question::ShuffleAnswers