Array index out of range

StreamReader fileReader = new StreamReader(filepath, true);

        //read the text file
        filecontent = fileReader.ReadToEnd();

        //close the file when done reading

        //split the text file into lines
        lines = filecontent.Split("


        //list of nodes and int's
        List<Vector3> nodesList = new List<Vector3>();
        List<int> intList = new List<int>();
        int mode = 0;


        for (int l = 0; l < lines.Length;l++)
            values = lines[l].Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            if( values[0] == "NODES")
                mode = 1;
            if( values[0] == "TRIANGLES")
                mode = 2;

i get the error(Array index out of range) at the if(values[0] == Nodes)

i don’t understand why it is giving the error.

I would be very thankfull if somebody could explain what i did wrong.

thank you in advance

Maybe Split return empty array and you try to access to first element which just isn’t exist. You should check it earlier:if(values.Length > 0). I hope this helps.