gpt4 book ai didi

c# - C#对象层次结构

转载 作者:太空宇宙 更新时间:2023-11-03 18:13:15 26 4
gpt4 key购买 nike

我有一个单元列表,每个列表都有一个站列表。

有时我需要获取工作站的父单元。

我将如何实现这种层次结构?


我应该在站对象中将父单元格保留为属性吗?
我是否应该仅将父单元格ID保留在Station对象中?
有什么不同吗?

最佳答案

如果我是你,我将创建两个类:

public class Cell {
...
public List<Station> Stations {
get {...}
}

protected Station AddStation() {
Station result = new Station(this);
Stations.Add(result);
return result;
}
}

public class Station {
public Station(Cell cell) {
this.cell = cell;
}
Cell cell;
public Cell Cell {get {return cell;}}
}


具有此结构,您始终可以从Station对象访问单元。

关于c# - C#对象层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10833991/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com