Share via

Load Array in Blazor

Anonymous
2023-11-16T12:28:13.1333333+00:00

I cloned this app from GitHub, I want to enhance it , if user answers any question incorrectly , I want to display that question ant the end , where the total points scored and total answers are displayed .

For that I am planning to load failed questions into any array , but I am getting an error , how do I load failedquestions[failedIndex] and display the same once the quiz is completed

Code from QuizCardBase.cs

  protected void OptionSelected(string option)
        {
            if (option == Questions[questionIndex].Answer)
            {
                score++;
            }
            { //failedquestions[failedIndex] = Questions[questionIndex].QuestionTitle;
              //  failedIndex++;


            }
            questionIndex++;
        }

https://github.com/KalyanAllam/Quizzing

Developer technologies | .NET | Blazor
0 comments No comments

Answer accepted by question author

Anonymous
2023-11-16T13:43:03.56+00:00

Hi @Kalyan A,

You could try below code:

private string[] failedQuestions;
private int failedIndex;

public QuizCardBase()
{
    failedQuestions = new string[100];
    failedIndex = 0;
}

protected void OptionSelected(string option)
{
    if (option == Questions[questionIndex].Answer)
    {
        score++;
    }
    else
    {
        failedQuestions[failedIndex] = Questions[questionIndex].QuestionTitle;
        failedIndex++;
    }
    questionIndex++;
}

protected void DisplayFailedQuestions()
{
    for (int i = 0; i < failedIndex; i++)
    {
        Console.WriteLine(failedQuestions[i]); 
    }
}



Best Regards,

Jalpa Panchal


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.