Search This Blog

Sunday 6 August 2017

Error CS0121 The call is ambiguous between the following methods or properties

Compiler Error CS0121 The call is ambiguous between the following methods or properties: 'TestMethod' and 'TestMethod'

The compiler was not able to call one form of an overloaded method. In other word Compiler can not decide which overload method should use.

C# Code

public class Parent
{
    public double Add(int i, double d)
    {
        return (double)i + d;
    }

    public double Add(double d, int i)
    {
        return d + (double)i;
    }
}

Call above function from Main function

static void Main(string[] args)
{
    Parent p1 = new Parent();
    double result1 = p1.Add(1, 2.2); // result1 = 3.2
    double result2 = p1.Add(1.1, 2); // result1 = 3.1
    double result3 = p1.Add(1, 2);   // Get Compiler Error CS0121
    Console.ReadKey();
}

1 comment:

  1. Your blog is very interesting. Thank you for your sharing this post. I want more information in your blog...!
    MS Azure Online Training

    ReplyDelete

Elasticsearch - Nodes, clusters, and shards

Elastic Stack Video - Load your gun in short time.   Beginner's Crash Course to Ela...

Recent Post