Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# deeply related children

// Usage:
var relativeChildren = Traverse(myListOfRelativeChildren, item => item.Children);

relativeChildren.ToList().ForEach((child) => 
{
	// this way you can even get the properties of child objects
	Console.WriteLine(child.Id);
});

public static IEnumerable<T> Traverse<T>(
  	T root, 
    Func<T, IEnumerable<T>> childSelector)
{
    var stack = new Stack<T>();
    stack.Push(root);

    while (stack.Any())
    {
        var next = stack.Pop();
        yield return next;
        foreach (var child in childSelector(next))
            stack.Push(child);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: jtoken value is not exact 
Csharp :: instance vs initiate 
Csharp :: c# code for simplex method 
Csharp :: Console.WriteLine($"Hello {Ana.ToUpper($)}!"); 
Csharp :: c# 9.0 dynamic nedir 
Csharp :: how do make internet 
Csharp :: How to truncate a decimal without rounding 
Csharp :: OBSERVER 
Csharp :: c sharp switch forms 
Csharp :: string in char list f# 
Csharp :: windowsform mail sender app 
Csharp :: c# how to output array 
Csharp :: ASP.NET Web Forms TextBox 
Csharp :: catwherehouse 
Csharp :: linq contains null 
Csharp :: How to scroll to bottom of ListBox 
Csharp :: C# if...else Statement 
Csharp :: .net core api routing not working 
Csharp :: gersener waves 
Csharp :: translate english to spanish 
Csharp :: C# list of unique values with group and counts 
Csharp :: replace bar c# 
Csharp :: c# switch expression 8.0 
Csharp :: c# crud observablecollection -mvvm 
Csharp :: character stay in ground unity 3d 
Csharp :: Convert any class to a keyvaluepair 
Csharp :: c# call by reference 
Csharp :: qcombobox delegate text filter 
Csharp :: unity Polymorphism 
Csharp :: entity framework dynamic search 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =