【发布时间】:2023-04-11 10:31:02
【问题描述】:
我在使用 Visual Studio 显式实现 n 接口时遇到了这个问题。所以接口包含属性,但是当我在抽象类中显式实现属性时,编译器会抛出错误“修饰符'public'对此项无效”。
参考下面给出的代码。
interface ITest
{
bool MyProperty { get; set; }
}
internal class Test : ITest
{
public bool ITest.MyProperty
{
get
{
return false;
}
set { }
}
}
【问题讨论】:
-
所以去掉
public修饰符。
标签: c# properties interface explicit