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

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,620 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jalpa Panchal-MSFT 705 Reputation points Microsoft Vendor
    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.


0 additional answers

Sort by: Most helpful

Your answer

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