use a for loop
for (var i = 0; i < questions.Length; ++i)
{
<p>Question</p>
<div>
<div>@questions[i].Question</div>
</div>
<br>
<p>Answer</p>
<div>
<div>@questions[i].Answer</div>
</div>
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How do I declare Lists in Blazor MAUI App?, the below code gives error. Blazor MAUI App giving Error with List. I want to create a quiz app using question and answers. Load questions ,answers into list. Random numbers can be increased from 1 to n.
@page "/"
<h1>Counter</h1>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<p>Question</p>
<div>
<div>@question</div>
</div>
<br>
<p>Answer</p>
<div>
<div>@answer</div>
</div>
<br>
@code {
private int number;
private Question[] questions;
questions = new[] {
new Question { Id = 1, Question = "Capital of France", Answer = "Paris" },
new Question { Id = 2, Question = "Capital of Japan", Answer = "Tokyo" }
};
private void IncrementCount()
{
Random rand = new Random();
int number = rand.Next(1, 3);
var question = from s in Questions
where s.Id == number
select s.Question;
var answer = from s in Questions
where s.Id == number
select s.answer;
}
}
use a for loop
for (var i = 0; i < questions.Length; ++i)
{
<p>Question</p>
<div>
<div>@questions[i].Question</div>
</div>
<br>
<p>Answer</p>
<div>
<div>@questions[i].Answer</div>
</div>
}