Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have below interface.

internal Interface I1
{
IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters);
IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters, string str);
}

When I am implementing the I1 interface, in my class by overriding the methods in base class compiler is reaching the first method always though I am passing value with str variable only.

Could you please help me in this.

What I have tried:

When I am implementing the I1 interface, in my class by overriding the methods in base class compiler is reaching the first method always though I am passing value with str variable only.
Posted
Updated 8-Apr-21 6:10am
Comments
BillWoodruff 8-Apr-21 4:10am    
"compiler is reaching the first method always though I am passing value with str variable only."

doesn't make sense: both methods require: IDbDataParameter[] parameters

1) C# is case sensitive: Interface is not the same as interface - you need the latter.

2) If I correct that and implement your code, I get what I expect:
C#
internal class IDbDataParameter { }
internal interface I1
    {
    IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters);
    IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters, string str);
    }
internal class C1 : I1
    {
    public IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters)
        {
        Debug.WriteLine("In 1 param");
        return new IDbDataParameter[0];
        }

    public IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters, string str)
        {
        Debug.WriteLine("In 2 param");
        return new IDbDataParameter[0];
        }
    }

C#
C1 c1 = new C1();
c1.TransformParameters(new IDbDataParameter[0]);
c1.TransformParameters(new IDbDataParameter[0], "Hello World");

In 1 param
In 2 param
Are you sure your original code compiled error free and you weren't running an earlier version?
 
Share this answer
 
Comments
BillWoodruff 8-Apr-21 6:26am    
OP: "... compiler is reaching the first method"

suggests it compiles ?
OriginalGriff 8-Apr-21 6:42am    
Or it didn't and it's running a previous version of the software because a new EXE file wasn't generated?
Thanks for your reply. could you please look the below code and suggest where I am missing.

The class implementation is like the below.
internal class C1 : I1
    {
    protected virtual IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters)
        {
        Debug.WriteLine("In 1 param");
        return new IDbDataParameter[0];
        }

    protected virtual IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters, string str)
        {
        Debug.WriteLine("In 2 param");
        return new IDbDataParameter[0];
        }


and the methods are getting over rided like below

internal class C2 
    {
    protected override IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters)
        {
        Debug.WriteLine("In 1 param");
        return new IDbDataParameter[0];
        }

    protected override IDbDataParameter[] TransformParameters(IDbDataParameter[] parameters, string str)
        {
        Debug.WriteLine("In 2 param");
        return new IDbDataParameter[0];
        }
 
Share this answer
 
Comments
Richard Deeming 9-Apr-21 4:46am    
This is not a solution to your question.

Click the green "Improve question" link and update your question to add the new details. Click the "Have a Question or Comment?" button under Bill's solution, and ask him to take a look at your updated question. Then delete this non-solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900