c# - 循环参考 Delphi vs C#
问题描述
我正在尝试在 Delphi 中建立一些类关系。
在 C#、PHP 等其他语言中,我对这些关系没有任何问题,但在 Delphi 中,我有一个循环引用错误。
为什么这个错误发生在 Delphi 而不是 C#?其他语言如何以及为什么可以处理循环引用而 Delphi 不能?C# 是如何处理这个问题的?
Delphi 有没有不使用接口或单机的解决方案?
德尔福
爸爸.pas
unit Dad;
interface
uses
System.Generics.Collections, Child;
type
TDad = class
private
{ private declarations }
FName: string;
FChildren: TObjectList<TChild>;
protected
{ protected declarations }
public
{ public declarations }
property Name: string read FName write FName;
property Children: TObjectList<TChild> read FChildren write FChildren;
end;
implementation
end.
孩子.pas
unit Child;
interface
uses
Dad;
type
TChild = class
private
{ private declarations }
FName: string;
FDad: TDad;
protected
{ protected declarations }
public
{ public declarations }
property Name: string read FName write FName;
property Dad: TDad read FDad write FDad;
end;
implementation
end.
夏普
爸爸.cs
using System;
using System.Collections.Generic;
using System.Text;
using CircularReferenceTest.SecondNamespace;
namespace CircularReferenceTest.FirstNamespace
{
public class Dad
{
public String Name { get; set; }
public IList<Child> Children { get; set; }
}
}
儿童.ps
using System;
using System.Collections.Generic;
using System.Text;
using CircularReferenceTest.FirstNamespace;
namespace CircularReferenceTest.SecondNamespace
{
public class Child
{
public String Name { get; set; }
public Dad Dad { get; set; }
}
}
解决方案
推荐阅读
- html - 列填充:自动;没有高度溢出div
- java - 对 MongoDB 的 java 驱动程序中的重复唯一键错误做出反应
- javascript - 检查 Cloud Firestore 查询是否返回某些内容
- javascript - 在javascript中将数组声明为函数是什么意思?
- php - 登录后不跳转
- excel - 调用宏时如何修复溢出错误
- filter - Tableau:使用聚合进行筛选
- python - Tensorflow 使用 cpu (tensorflow) 与 gpu (tensorflow-gpu) 后端显示不同的行为
- typescript - Intellisense 表示 Class1 和 Class2 中不存在该属性
- python - 在 Python 中清理后保存数据帧