I want to ask you what's the most efficient way of going through each child object of a Parent. For example I have a class which is:
public class Asset
{
public string Id { get; set; }
public Asset Child { get; set; }
}
static void Main(string[] args)
{
var x = new Asset() { Id = "1" };
var y = new Asset() { Id = "2" };
var z = new Asset() { Id = "3" };
x.Child = y;
y.Child = z;
z.Child = null;
var listOfChildItems = new List<Asset>();
listOfChildItems = GetAllChildren(x);
}
static List<Asset> GetAllChildren(Asset asset)
{
// TODO:
}
This class might contain Child which contains another child and so on. So what I want is to obtain whole list of Child items of Child items recursively until Child item is not equal null.