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 Properties

Travis John Villanueva
Travis John Villanueva
5,052 Points

can you help me point out my mistakes?

Just a simple override of properties. What did i missed?

RepeatDetector.cs
namespace Treehouse.CodeChallenges
{
    class RepeatDetector : SequenceDetector
    {
        protected override string Description { get; } = "Detects repetitons";
        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;
        }
    }
}
SequenceDetector.cs
namespace Treehouse.CodeChallenges
{
    class SequenceDetector
    {
        protected virtual string Description {get;}= "";

        public virtual bool Scan(int[] sequence)
        {
            return true;
        }
    }
}

1 Answer

Steven Parker
Steven Parker
229,744 Points

You have a few issues to address.

  • these properties are supposed to be public, but you made them protected
  • the original property in SequenceDetector.cs had valid syntax, but you changed it to an invalid syntax
  • you used the same invalid syntax in your override
  • you spelled "repetitons" (missing an "i") instead of "repetitions"