.net - How do I create a Generic Linked List? -


i trying use generic linked list hold workflow steps in application. here how i'm persisting database.

orderid  workflowstepid  parentworkflowstepid
178373    1                         null
178373    2                         1
178373    3                         2

i dataset in datareader object. loop through datareader , create workflowstep object includes workflowstepid property , parentworkflowstepid property. add first object linkedlist using .addfirst() method. next idea create next object , insert after object in linkedlist it's workflowstepid equal new object's parentworkflowstepid. can't figure out of find object in linkedlist. find() method asking value, don't understand value is, or how can find it.

so mean you're using linked list class in framework?

if so, find method doesn't want to. want version takes predicate. easier if class exposed iterator of linkedlistnode<t>. fortunately it's easy provide extension method that:

public static ienumerable<linkedlistnode<t>> getnodes<t>(this linkedlist<t> list) {     linkedlistnode<t> current = list.first;     while (current != null)     {         yield return current;         current = current.next;     } } 

then can (and stress of untested):

var node = list.getnodes().firstordefault(x.value.workflowerstepid = parentworkflowstepid); if (node != null) {     list.addafter(node, newitem); } else {     // whatever. add tail? } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -