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

Stepas Loiba
Stepas Loiba
11,180 Points

Override the Scan method to return true if any value in the array is a repeat of the value immediately preceding it.

Can some one have look in code and give few pointers why i have error message error CS1525: Unexpected symbol )', expecting.',thank you in advance.

SequenceDetector.cs
namespace Treehouse.CodeChallenges
{
    class SequenceDetector
    {
        public virtual bool Scan(int[] sequence)
        {
            return true;
        }
    }
}
RepeatDetector.cs
namespace Treehouse.CodeChallenges
{
    class RepeatDetector : SequenceDetector
    {
        public override bool Scan(int[] sequence)
        {
            foreach(int sequance in int)
            {
                int i = 1;
                if(sequence[i] == sequence[i - 1])
                {
                   return true;
                }
                else
                {
                    return false;
                }
            }
        }

    }
}

2 Answers

Steven Parker
Steven Parker
229,785 Points

It looks like you have the right basic idea.

Perhaps you only need a few hints:

  • your foreach expression syntax is not correct — but you don't really need foreach here
  • you can make use of more of your existing code with a simple for loop
  • remember not to "return false" until the entire loop has finished checking for duplicates

I'll bet you can get it from here.

Stepas Loiba
Stepas Loiba
11,180 Points

Thank you Steven again:) you helping me a lot.have nice day.very helpful post.