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# Abstraction Interfaces

can't solve challange 2 of 2

Challenge Task 2 of 2

In Increment.cs create a class named Increment that implements the IUnaryOperation interface. The Perform method should increment the value passed in by one. Important: In each task of this code challenge, the code you write should be added to the code from the previous task. Restart Preview Get Help Check Work IUnaryOperation.cs Increment.cs

1 namespace Treehouse.CodeChallenges 2 { 3 public class Increment : IUnaryOperation { 4 ā€‹ 5 public double Perform(double value) { 6 return value += 1;
7 } 8 } 9 } 10 ā€‹

IUnaryOperation.cs
 namespace Treehouse.CodeChallenges
{
    interface IUnaryOperation 
    {
        double Perform(double value);
    }

}
Increment.cs
namespace Treehouse.CodeChallenges
{
    public class Increment : IUnaryOperation {

        public double Perform(double value) {
            return value += 1;   
        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,198 Points

Your code looks fine, and it passes the challenge. Good job. :+1:

You didn't mention what kind of problem you were having. But I suggest you try again, and simply paste the answer from above into the challenge (that's what I did, and it passed).

Why would you implement the interface when the method in the class seems like a regular method.

thanks steven