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 trialshawn khah
15,082 Pointshelp plz
Challenge Task 1 of 1
SequenceDetector now contains a Description property. In RepeatDetector, override the Description property to return "Detects repetitions". Important: In each task of this code challenge, the code you write should be added to the code from the previous task. Restart Get Help Check Work RepeatDetector.cs SequenceDetector.cs
1 namespace Treehouse.CodeChallenges 2 { 3 class RepeatDetector : SequenceDetector 4 { 5 public override bool Scan(int[] sequence) 6 { 7 if(sequence.Length < 2) 8 { 9 return false; 10 } 11 ā 12 for(int i = 1; i < sequence.Length; ++i) 13 { 14 if(sequence[i] == sequence[i-1]) 15 { 16 return true; 17 } 18 } 19 ā 20 return false; 21 } 22 } 23 } 24 ā
namespace Treehouse.CodeChallenges
{
class RepeatDetector : SequenceDetector
{
public override bool Scan(int[] sequence)
{
if(sequence.Length < 2)
{
return false;
}
for(int i = 1; i < sequence.Length; ++i)
{
if(sequence[i] == sequence[i-1])
{
return true;
}
}
return false;
}
}
}
namespace Treehouse.CodeChallenges
{
class SequenceDetector
{
public string Description => "";
public virtual bool Scan(int[] sequence)
{
return true;
}
}
}
2 Answers
tjgrist
6,553 PointsFirst, make the Description property in SequenceDetector overridable by adding the virtual keyword:
public virtual string Description => "";
then in the RepeatDetector class, add the property by overriding it's parent's property:
public override string DescriptIon => "Detects Repetitions";
shawn khah
15,082 Pointsthank's tj
Calvin Secrest
24,815 PointsCalvin Secrest
24,815 PointsI seem to not be able to compile this syntax I used the same code in my challenge
tjgrist
6,553 Pointstjgrist
6,553 PointsAh yes, that must be because i had a typo in the override property. Instead of 'DescriptIon' make sure you put 'Description' (lowercase 'i')
Calvin Secrest
24,815 PointsCalvin Secrest
24,815 PointsOk thanks and I'm confused on the RepeatDetector class, where do I add the property?
tjgrist
6,553 Pointstjgrist
6,553 PointsAnywhere except in the scan method.