Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# Intermediate C# Polymorphism Virtual Methods

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

anyone can help with an answer here?