2
Answers

Interface

Krunal Parate

Krunal Parate

9y
350
1
if i want to implement 2 interfaces in one class but if both interface contain same method with same name with same definaition. can we Implement it.
eg:-
interface IClass
{
int sum(int x, int y);
void mult(int x, int y);
}
interface IClass2
{
int sum(int x, int y); 
void div(int x, int y);
}
 here sum method has same name and same definition
Answers (2)
0
pritaeas

pritaeas

NA 3.1k 859 9y
See this example on MSDN. They can either share the same method, or explicitly implement a different one.
 
https://msdn.microsoft.com/en-us/library/ms173157.aspx 
0
Mukesh Kumar

Mukesh Kumar

NA 17.8k 3.7m 9y
Yes, you can use it.. see below a demo example..
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Globalization;
namespace ConsoleApplication2
{
public interface IClass
{
int sum(int x, int y);
void mult(int x, int y);
}
public interface IClass2
{
int sum(int x, int y);
void div(int x, int y);
}
public class Program :IClass, IClass2
{
static void Main(string[] args)
{
IClass ic = new Program();
var sumvalue=ic.sum(3, 4);
IClass2 ic2 = new Program();
var sumvalue2 = ic2.sum(4, 6);
Console.ReadLine();
}
}
}
 
Please mark as answer if it will help you.
thanks