条件<expected> .Equals':接口不能声明类型

时间:2016-05-19 11:14:52

标签: c#

我收到此错误:

  

Condition.Equals':接口无法声明类型”。

我该如何正确地做到这一点?

 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));
            }
        }

1 个答案:

答案 0 :(得分:0)

将类声明移到界面;您在界面中可以做的就是声明方法属性

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));
  }
}