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

Alan Mills
Alan Mills
31,712 Points

There aren't any preview options available on this quiz to identify / troubleshoot.

This particular quiz is missing a preview / editor button, prohibiting me from troubleshooting my quiz.

RepeatDetector.cs
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;
        }

        public override string Description {get; } = "Detects repetitions";
    }
}
SequenceDetector.cs
namespace Treehouse.CodeChallenges
{
    class SequenceDetector
    {
        public string Description => "";

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

2 Answers

Steven Parker
Steven Parker
231,248 Points

You seem to have discovered a bug! You might want to report this to the Support folks. A screenshot of the error message telling you to use the preview button (and with none next to it) might be helpful (and funny!).

In the meantime, here's a few hints regarding passing the challenge:

  • take a look at the definition in SequenceDetector.cs and use it as a model for expression-bodied syntax
  • remember that you can only override properties that are declared virtual
Patrick McLeod
Patrick McLeod
5,913 Points

Hi Iยดve a question regarding this challenge. Why is the public access modifier used instead of "protected"? Cheers, PM

Steven Parker
Steven Parker
231,248 Points

In future, it's always better to start a fresh question for a new topic. Otherwise, your question might only be seen by the person that asked the other one and anyone who posted an answer to it (and no guarantees even they would).

But the "public" access allows the method to be used by any code that creates or references an instance of this class. If it were "protected", the method could only be used from inside the class itself, or a subclass created from it.

Patrick McLeod
Patrick McLeod
5,913 Points

Thanks for your prompt reply. Ok, I get it but still... Considering RepeatDetector.cs is a subclass of RepeatDetector.cs, it should have worked, right? Isnt RepeatDetector.cs a subclass created from RepeatDetector.cs?

Steven Parker
Steven Parker
231,248 Points

Since you did make a fresh question, let's continue the thread there.