无法通过接口的保护集实现属性
我有一个界面,该界面具有带有公共获取和受保护集的属性。
但是,当我在课堂上实施此功能时,我会发现一个错误,说它必须公开。
我的界面看起来像这样:
public interface ISegment
{
INode NodeA { get; protected set; }
INode NodeB { get; protected set; }
public sealed void SetNodeA(INode node) => NodeA = node;
public sealed void SetNodeB(INode node) => NodeB = node;
}
我的类段:Isegment
是否属于这样的属性:
[SerializeField]
protected Node _nodeA;
public INode NodeA
{
get => _nodeA;
protected set => _nodeA = value as Node;
}
[SerializeField]
protected Node _nodeB;
public INode NodeB
{
get => _nodeB;
protected set => _nodeB = value as Node;
}
我得到了此错误:
'Segment' does not implement interface member 'ISegment.NodeA.set'
'Segment' does not implement interface member 'ISegment.NodeB.set'
我在这里误会了什么?
I have an interface which has a property with public get and protected set.
Yet when I implement this in my class i get an error saying it must be public.
My interface looks like this:
public interface ISegment
{
INode NodeA { get; protected set; }
INode NodeB { get; protected set; }
public sealed void SetNodeA(INode node) => NodeA = node;
public sealed void SetNodeB(INode node) => NodeB = node;
}
My class Segment : ISegment
has the properties declared like this:
[SerializeField]
protected Node _nodeA;
public INode NodeA
{
get => _nodeA;
protected set => _nodeA = value as Node;
}
[SerializeField]
protected Node _nodeB;
public INode NodeB
{
get => _nodeB;
protected set => _nodeB = value as Node;
}
And i get this error:
'Segment' does not implement interface member 'ISegment.NodeA.set'
'Segment' does not implement interface member 'ISegment.NodeB.set'
What am i misunderstanding here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样做吗,
但是问题是,你为什么想要那个?为什么
受保护的集合
?您也可以这样做。 (由于接口中的默认实现,在这里无济于事)
更新:编辑了代码以显示更准确的信息,如何访问属性
Do it like this
but the Question is, why do you want that? Why
protected set
?You can do it like this also. (Not helps here because of default implementation in the interface)
Update: Edited the code to show more exactly, how to access the properties