0

I am getting this error:

"Condition.Equals': Interfaces cannot declare types".

How do I do this correctly?

 public interface Condition<Expected> {

        public bool verify(Expected expected, object actual);

        public class Equals : Condition<object> {   

            public bool verify(object expected, object actual) {
                return expected==actual || (expected!=null && expected.Equals(actual));
            }
        }
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
King Kong
  • 1
  • 1

1 Answers1

0

Move class declaration outside the interface; all you can do within the interface is declaring methods and properties:

public interface Condition<Expected> {
  // you can't declare interface method as public or, say, private: 
  // it's the implementing class that provides the access modifier
  bool verify(Expected expected, object actual);
}

public class Equals : Condition<object> {   
  public bool verify(object expected, object actual) {
    return expected == actual || (expected != null && expected.Equals(actual));
  }
}
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
  • I'm fairly new to C#, just translated this from my Java code so I'm still getting the hang of it. Thanks! – King Kong May 19 '16 at 11:46