C# - Can't pass Out with an Override method

132 views Asked by At

I have a method very similar to the example below, and it won't let me out the outItem.

    public override bool myMethod(string item, out string outItem)
    {
        outItem = "";
        return true;
    }

It keeps giving the the following error:

"no suitable method found to override"

If I remove the override, the error goes away. How can I fix this problem?

2

There are 2 answers

0
Servy On BEST ANSWER

It would appear that the method in the base class doesn't mark that parameter as out. You need to conform to the base class's signature. If you can change the base class to mark the method as out, then you can mark it as such on the derived type as well. If you can't, then you won't be able to override the method, you'll have to create a new method instead.

3
Andy On

It sounds like the base class signature of myMethod doesn't use out for the second parameter. You can't just add that in because it changes the method signature. If you have control of the base class you can add it, but if not you'll need to remove the override.