-7

I want to list the auteur added in a Winform of an API

I want to list the auteur added in a Winform of an API

Here is the message error

Here is the message error

I tried to get the "auteur" with textBox3.Text = Program.ouvrage.Auteur[this.cmp]; but i have this error : Index was out of range. Must be non-negative and less than the size of the collection. Arg_ParamName_Name'

Rand Random
  • 7,300
  • 10
  • 40
  • 88
  • 3
    [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) -- [How to ask](https://stackoverflow.com/help/how-to-ask) -- [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Jimi Jan 10 '23 at 18:33

1 Answers1

-1

Your list doesn't contain items and you are trying to read the first item ([0]), that not exists.

Try something like this: The validation must be always less than the quantity and the quantity must be greater than zero on Count() property:

if(this.cmp < Program.ouvrage.Auteur.Count() && Program.ouvrage.Auteur.Count() >0)
{
textBox3.Text = Program.ouvrage.Auteur[this.cmp];
}
else
{
textBox3.Text = "The list doesn't contain items";
}
xaotix
  • 39
  • 6