How to avoid the error "the call is ambiguous ..." when writing static and non-static methods in C #?

I have several classes that represent business transaction calls: executing the corresponding stored procedures.

Now it looks like this:

public static class Request
{
    public static void Approve(..) {
        using(connection) {
            command.Text = "EXEC [Approve] ,,"]
            command.ExecuteNonQuery();
        }
    }
}

And I want to make them more thread safe:

public class Request {
    public static void Approve(..) {
        new Request().Approve(..);
    }

    internal void Approve(..) {
        using(connection) {
            command.Text = "EXEC [Approve] ,,"]
            command.ExecuteNonQuery();
        }
    }
}

But getting the following error message:

The call is ambiguous between the following methods or properties: 'MyNamespace.Request.Approve (..)' and 'MyNamespace.Request.Approve (..)

How can I make note that I am calling a non-static instance method from static?

Or can I not do this without renaming one of the methods? Or moving a static method to another class, etc.

+3
2

(, requestVar.Approve()), , . Request.Approve().

+3

# . , - , .

, Approve() , , , .

, ... () , - - .

+4

Source: https://habr.com/ru/post/1719912/


All Articles