首页 新闻 会员 周边

c# 修饰符“public”对该项无效

0
[已解决问题] 解决于 2017-02-15 18:02

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();


}
}
}

代码如上,报错行标黄

hannah520的主页 hannah520 | 菜鸟二级 | 园豆:204
提问于:2017-02-15 16:42
< >
分享
最佳答案
0

显示接口成员实现中不能包含访问修饰符。

显示接口成员属于接口的成员,不属于类的成员。只能通过接口对象来访问。

hannah520 | 菜鸟二级 |园豆:204 | 2017-02-15 16:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册