C# Intermediate C# Polymorphism Virtual Methods

R S
R S
2,225 Points

I am not sure why I am getting the error index is out of bounds of the array.

I am not sure why I am getting an error when running this code that the index is outside of the array bounds

SequenceDetector.cs
namespace Treehouse.CodeChallenges
{
    public class SequenceDetector 
    {
        public virtual bool Scan(int[] sequence)
        {
            return true;
        }
    }


}
RepeatDetector.cs
namespace Treehouse.CodeChallenges
{
public class RepeatDetector : SequenceDetector
    {

       // 65, 75, 75
       public override bool Scan(int[] sequence)
       {
            int precedingValue = 0;
            int storeFirstValue = 0;
            foreach(int sequenceOne in sequence)
            {
               if (storeFirstValue == sequence[sequenceOne])
               {
                  return true;
               }
               storeFirstValue = sequence[sequenceOne];
              //return false;
            }
            return false;
       }
    }
    }

1 Answer

R S
R S
2,225 Points

anyone can help with an answer here?