Check if Array element has value or not

How do I check if an Array element has a value assigned?

This is my current code…

for (int i = 0; i <= monstersList.Length; i++)
            {
                Debug.Write("in loop");
                if (monstersList[i] != null)
                {
                    //do stuff with free element
                }
            }

…and this is my solution…

 if (monstersList[i] != null)

…but it keeps throwing out the ‘out of range error’ so clearly my solution is wrong.

It’s not wrong, the error states that you’re trying to address an invalid index, which happens due to your condition ’ <= '. It should only be ’ < '.