两个接口的实例可以互相引用吗?
使用 C#
Interface A,
Interface B,
Class AA:A
{
public AA(A a)
{
//...
}
}
Class BB:B
{
public BB(B b)
{
//...
}
}
代码是否可以正常工作并且不会导致循环引用问题?
Using C#
Interface A,
Interface B,
Class AA:A
{
public AA(A a)
{
//...
}
}
Class BB:B
{
public BB(B b)
{
//...
}
}
are the code works fine and not cause the circular reference problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不呢?除了语法之外,自相似结构在计算机科学中随处可见。考虑一棵二叉树:每个节点都有对另外两棵树的引用(由它们的根节点表示)。制作此类树的典型方法是使用对该类型的其他实例的两个引用而不是一个引用来构造类型。
更一般地说,类型系统中的循环与对象图中的循环不同。通常第一个是设计使然,但第二个有可能变成错误。
Why not? Syntax aside, self-similar structures appear all over computer science. Consider a binary tree: each node has a reference to two other trees (represented by their root nodes.) A typical way to make such a tree is a type that is constructed with not one, but two references to other instances of the type.
More generally, cycles in the type system are not the same as cycles in the object graph. Usually the first is by design, but the second has a way of turning into bugs..