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 trialSyed Abbas
4,762 PointsScan Method in Polymorphism - overriding methods
Hi I am new to c# so not sure how to develop this scan method. Any help will be appreciated. Thanks.
namespace Treehouse.CodeChallenges
{
class SequenceDetector
{
public virtual bool Scan(int[] sequence)
{
return true;
}
}
}
namespace Treehouse.CodeChallenges
{
class RepeatDetector:SequenceDetector
{
public override bool Scan(int[] sequence)
{
int previous = 0;
for(int i=0;i<=sequence.Length;i++)
{
int current = sequence[i];
if(previous==current)
{
return true;
}
previous = sequence[i];
}
}
}
}
1 Answer
Simon Owerien
12,829 PointsYou are currently checking in the first iteration of the loop if (0==sequence[0]). You should modify your loop and the previous variable in a way so you either skip the first iteration or you check the right variables. A good hint would be to start your loop not at index 0 but at index 1.