在C#中搜索嵌套列表

问题描述 投票:0回答:1

我有一个对象列表

public class DebtorTreeModel {

        public int ID { get; set; }      
        public string text { get; set; }
        public int  ParentID { get; set; }
        public int BillingParentID { get; set; }
        public int ReportingParentID { get; set; }
        public bool HasChildren { get; set; }


        public List<DebtorTreeModel> items { get; set; }


    }

我将像树结构一样基于该对象添加节点。我的代码要求将子节点添加到内部节点,但是我找不到内部节点,我使用

 List<DebtorTreeModel> rootDebtorNode  ;  //This list has been loaded with all parent nodes though
 rootDebtorNode.Find(t => t.ID == debtChild.BillingParentId).items.Add(debtorTreeModelChild);

代码的最后一行无法获取该特定的内部节点,即使它存在也可以提供一些帮助

c# tree nested structure
1个回答
0
投票

除了需要一个有效示例的注释之外,为您指出正确的方向,我还将研究Dijkstra的算法和图形数据结构。在此结构上有很多c#示例。例如

http://blog.boxofbolts.com/dotnet/graphs/2015/08/31/working_with_graph_data_structures_dot_net/

https://github.com/YaccConstructor/QuickGraph

我的假设是,根据您的示例,您正在尝试这样做。乐意为您解决更详细的问题。

© www.soinside.com 2019 - 2024. All rights reserved.