using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Test10_3
{
interface ImyInterface1
{
int Add();
}
interface ImyInterface2
{
int Add();
}
class Myclass:ImyInterface1,ImyInterface2
{
public int ImyInterface1.Add()
{
int x = 3;
int y = 7;
return x + y;
}
public int ImyInterface2.Add()
{
int x = 3;
int y = 7;
int z = 5;
return x + y + z;
}
}
class Program
{
static void Main(string[] args)
{
Myclass myclass = new Myclass();
ImyInterface1 imyinterface1 = myclass;
ImyInterface2 imyinterface2 = myclass;
Console.WriteLine(imyinterface1.Add());
Console.WriteLine(imyinterface2.Add());
Console.ReadLine();
}
}
}
代码如上,报错行标黄
显示接口成员实现中不能包含访问修饰符。
显示接口成员属于接口的成员,不属于类的成员。只能通过接口对象来访问。