-3

How to fix error "Index was out of range must be nonnegative and less than the size of the collection"?

    // Create new List called _identifiers
    private List<string> _identifiers = new List<string>();

    // Add identifiers to the Identifiable object
    public IdentifiableObject (string[] idents)
    {
        for(int i=0; i<idents.Length; i++)
        {
            idents [i] = _identifiers [i];
        }
    }

Screenshot of IndexOutOfRange

Koopakiller
  • 2,838
  • 3
  • 32
  • 47
Alex Wong
  • 11
  • 1

1 Answers1

0

Looks like the length of your _identifiers-array is less than the length of your idents-array. Thus, while you're looping through all identifiers until the max length of idents, you try to access an inexistent inxed of _identifiers.

In your case, _identifiers is empty, so it's clearly less long than your idents

UeliDeSchwert
  • 1,146
  • 10
  • 23