Force child class to override function of ancestor via parent

前端 未结 3 1204
死守一世寂寞
死守一世寂寞 2020-12-11 05:33

I am writing an algorithm which requires the user to create his own class which inherits from a class defined by me. However, the algorithm requires the user to override the

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 05:57

    You can create 2 new methods that will be abstract and will be called from GetHashCode and Equals your class.

    Example:

    public abstract ParentClass {
        public abstract int MyGetHashCode();
    
        public override int GetHashCode(){
            return MyGetHashCode();
        }
    
        // same thing for Equals
    }
    

提交回复
热议问题