Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
C#
class CustomCllection
    {
        C c1 = new XYZ();
        A a1 = new XYZ();
        B b1 = new XYZ();
        XYZ x = new XYZ();
        public void Check()
        {
            a1.i = 30;
            a1.Test1();
            a1.Test2();
            //-----------
            b1.k = 30;
            b1.Test2();
            b1.Test3();
            //----------------
            c1.i = 40;
            c1.k = 50;
            c1.m = 60;
            c1.Test1();
            c1.Test2(); // [Edit]Error is here
            c1.Test3();
            c1.Test4();
        }
    }
    interface A
    {
        void Test1();
        void Test2();
        int i { get;set;}
    }
    interface B
    {
        void Test2();
        void Test3();
        int k { get;set;}
    }
    interface C : B, A
    {
       new void Test3();
        void Test4();
        int m { get;set;}
    }
    class XYZ : C
    {
        public void Test1()
        {
            MessageBox.Show("Hello I am Test1");
        }
        void A.Test2()
        {
            MessageBox.Show("Hello I am Test2(A)");
        }
        void B.Test2()
        {
            MessageBox.Show("Hello I am Test2(B)");
        }
        public void Test3()
        {
            MessageBox.Show("Hello I am Test3");
        }
        public void Test4()
        {
            MessageBox.Show("Hello I am Test4");
        }
        int nn = 10;
        public int i
        {
            set { value = nn; }
            get { return nn; }
        }
        int nm = 10;
        public int m
        {
            set { value = nm; }
            get { return nm; }
        }
        int km = 10;
        public int k
        {
            set { value = km; }
            get { return km; }
        }

    }



Give Us Error:
Error 1 The call is ambiguous between the following methods or properties. [Edit] A.Test2() and B.Test2()
Can Any One Explain Why this ambiguous Occur.

[Edit] Added by DaveyM69
Posted
Updated 7-Sep-10 3:32am
v2
Comments
DaveyM69 7-Sep-10 9:33am    
Had you highlighted the line where the error occurs and included the FULL error message we could have solved this much more easily! I have done this for you.

Beacuase both A and B have a Test2 method with the same parameters (none).
As C is derived from both it doesn't know which to use.

Your other test instances are down cast to A or B so they use their respective methods.
 
Share this answer
 
The complete error message is :

The call is ambiguous between the following methods or properties: 'B.Test2()' and 'A.Test2()'

Which should help you to identify what the problem is
 
Share this answer
 

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