Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We do not do your homework here!

Hi,

I wanted to know, if I have more than 1 interface in a application having same method signature as below:

C#
public interface ISum1
    {
        int Sum(int a, int b);
    }



C#
public interface ISum2
    {
        int Sum(int a, int b);
    }



Now I have implemented these interfaces in to class as below:
C#
public class MainClass : ISum1, ISum2
    {

        public int Sum(int a, int b)
        {
            return a + b;
        }

    }


It is working fine with implementation of Interface ISum1, if I wanted to write the definition for method in ISum2 in a class, it is now allowing me to put the same method with same signatures, how can I proceed further.... Please help.

VJ
Posted
Updated 17-May-12 2:49am
v2

You need to implement the interfaces explicitly

See here..

http://msdn.microsoft.com/en-us/library/aa288461%28v=vs.71%29.aspx[^]

Have a look at this blog as well, which is exactly what you are trying to do

http://sandblogaspnet.blogspot.co.uk/2008/05/implementing-two-interface-having-same.html[^]
 
Share this answer
 
Comments
VJ Reddy 17-May-12 8:16am    
Good answer. 5!
Vijaykumar Vadnal 17-May-12 8:20am    
Thanks a lot Dylan, it helped me. :)
Explicity qualifying the methods with Interface names would help

C#
public interface ISum1
{
    int Sum(int a, int b);
}

public interface ISum2
{
    int Sum(int a, int b);
}
public class MainClass : ISum1, ISum2
{
    int ISum1.Sum(int a, int b)
    {
        
        return a + b;
    }
    int ISum2.Sum(int a, int b)
    {
        return a * b;
    }
}
public class Test
{
    
    public void  TestMethod()
    {
        int result;
        ISum1 is1 = new MainClass();
        result = is1.Sum(2,3);
        ISum2 is2 = new MainClass();
        result = is2.Sum(2,3);

       
    }


}
 
Share this answer
 
Comments
Prasad_Kulkarni 22-May-12 6:46am    
Good one +5!

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