質問

I have two classes in different projects.

The first, named GeneralConcept is at the namespace I.am.here and has a protected virtual method named DoSomething.

The second is named SpecificInstanceOfConcept and is at the namespace I.am.in.a.different.place and inherits from GeneralConcept.

I am trying to override the method. Have the same name, same inputs, same type and inheriting from the class where the method is implemented. However,
I keep getting an error saying

no suitable method to override

The way it is set up looks like this,

namespace I.am.here  
{ 
    public class GeneralConcept        
    {
        //stuff
        protected virtual MyType DoSomething(Inputs input)
        {
             //more stuff
        }
    }
}


namespace I.am.in.a.different.place  
{ 
   public class SpecificInstanceOfConcept : I.am.here.GeneralConcept
    {
        //yet more stuff
        protected override MyType DoSomething(Inputs input)
        {
             //even more stuff
        }
    }
}

Thank you for your help.

役に立ちましたか?

解決

Overriding across namespaces should not be an issue. That error indicates one of the following:

  • I.am.here.GeneralConcept.DoSomething is not marked as virtual, abstract, or override
  • I.am.here.GeneralConcept.DoSomething is not public or protected
  • the input (or output) type to I.am.here.GeneralConcept.DoSomething is different than your override.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top