0

I have 2 interfaces as you can see :

public interface i1
{
 void add(news a);
}

and

public interface i2
{
void add(file f);
}

These two interface has own implementation .I want to crate another interface called i3 that inherit both i1 and i2 and uses their implementation ?How can i do that?

public interface i3:i1,i2
{

}

In fact i want to get all methods inside i3 using i2,i1 implementation .because the implementation of i3 for that methods is same .

2 Answers 2

2

I'm not understanding your question, but this compiles properly

public interface I1
{
    int One { get; set; }
}

public interface I2
{
    int Two { get; set; }
}

public interface I3 : I1, I2
{
    int Three { get; set; }
}

// Implementation of I3 (which inherits I1 and I2)
public class Foo : I3
{
    public int One { get; set; }
    public int Two { get; set; }
    public int Three { get; set; }
}
Sign up to request clarification or add additional context in comments.

4 Comments

I don't need a class . i need an third interface
@EhsanAkbar You have a third interface. I3
you know i am using wcf service .i want to integrate all my interface inside one interface and define the final interface inside wcf
@EhsanAkbar I'm not sure what your question about inheritance of interface has to do with WCF at all. Have a quick read learn.microsoft.com/en-us/dotnet/articles/csharp/…
1

Interface is for declaration not for implementation. Instead you should declare whatever you want in i3 and inherit all your interfaces in class

public interface i1
{
  int Add(int num1, num2);
}

public interface i2
{
 int Multiply(int num1, num2);
}

public interface i3
{
 int Divide(int num1, num2);
}

public class Mathematics: i1, i2, i3
{
  public int Add(int num1, int num2)
 {
   //Your implementation
 } 
 public int Multiply(int num1, int num2)
 {
   //Your implementation
 } 

 public int Divide(int num1, int num2)
 {
   //Your implementation
 }  
}

If inheriting interface by interface itself is intended like

ICollection<T>

interface does you can inherit like a class inherit interface.

public interface i1
{
  int Add(int num1, int num2);
}

public interface i2 
{
 int Multiply(int num1, num2);
}

public interface i3 : i1, i2
{
  int Divide(int num1, int num2);
}

public class Mathematics:  i3
{
  public int Add(int num1, int num2)
 {
   //Your implementation
 } 
 public int Multiply(int num1, int num2)
 {
   //Your implementation
 } 

 public int Divide(int num1, int num2)
 {
   //Your implementation
 }  
}

Thus, when you inherit i3 in a class you will get everything you have declared in i1, i2, and i3. While inheriting i1 will provide only i1 memebers similarly for i2.

1 Comment

I don't need a class . i need an third interface

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.