i need blazor help
i'm trying to fill an array of players but the inputs are going blank as soon as you deselect them and i don't know why
12 Replies
if there are any fixes or any workarounds please lmk
It would be great if you could paste your code here instead of sending screenshots.
That makes it way easier to test your code and find out what's wrong.
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/When
numPlayer == 4
and you try to change the value in any input field you should get an exception.
What does that exception say?☹️
See you get an index out of bounds error. What does that tell you about the issue you are facing?
Which parts of your code can produce this specific exception?
You really should try figuring this out by yourself, because it's an sneaky error that can cause a lot of annoyance and it's worth to understand it.
A code snippet to exactly see what's wrong
The solution / explanation
Basically what happens is that all your inputs are bound to the loop variable
i
.
And because that increases one more time even after the for condition is fullfilled they try to modify players[4]
which does not exist.
And even if that wouldn't be the case they are all bound to the exact same index.
You got two options to fix this.
Either you copy i
into a local variable and bind player[yourLocali]
.
Or you use foreach
with an Enumerable.Range
like in the example above. this makes a lot of sense, thanks for the help!
i was able to solve the issue just by doing this
so yea like you said just copying i to a local variable
thank you a lot !!!
Good job! No Problem