简体   繁体   English

在 C# 中搜索嵌套列表

[英]Search a nested List in C#

I have a list of object我有一个对象列表

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; }


    }

I will be adding nodes based on this object as in a tree structure.我将在树结构中添加基于此对象的节点。 My code require to add child node to an inner node , but i am unable to find the inner node , I use我的代码需要将子节点添加到内部节点,但我找不到内部节点,我使用

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

The last line of code fails to fetch that particualr inner node , even if it exists, can some one help最后一行代码无法获取那个特定的内部节点,即使它存在,有人可以帮忙吗

In addition to the comment of needing a working example, to point you in the right direction i would look at Dijkstra's Algorithm and the graph data structure.除了需要一个工作示例的评论之外,为了给您指明正确的方向,我会查看 Dijkstra 的算法和图形数据结构。 There are plenty of c# examples on this structure.有很多关于这个结构的 c# 示例。 For example例如

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

https://github.com/YaccConstructor/QuickGraph https://github.com/YaccConstructor/QuickGraph

My assumption is this is what you are attempting to do based off your example.我的假设是这就是你试图根据你的例子做的事情。 Happy to help with a more detailed problem.很乐意帮助解决更详细的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM