C# Programming
12-12-2009, 12:46 AM
Hi,
Having a class with parent child relationships is quite common (I think), and I normally traverse such trees using recursion.
Class looks like this:
public class Product {
public List Parents {get; set;}
public List Children {get; set;}
public string Name {get; set;}
public override string ToString() { return Name; }
}
Recursion will look like this:
public void Dump(Product p) {
Console.WriteLine(p.ToString());
foreach (var child in p.Children)
Dump(child); // (1)
}
However, I was told by someone before that using threads will be faster and less expensive.
Can anyone send me a sample code of how to do this? I'm thinking that I should simply change (1) to a ParameterizedThreadStart... but maybe there's a better practice?
Thanks in advance.
Rafferty
Having a class with parent child relationships is quite common (I think), and I normally traverse such trees using recursion.
Class looks like this:
public class Product {
public List Parents {get; set;}
public List Children {get; set;}
public string Name {get; set;}
public override string ToString() { return Name; }
}
Recursion will look like this:
public void Dump(Product p) {
Console.WriteLine(p.ToString());
foreach (var child in p.Children)
Dump(child); // (1)
}
However, I was told by someone before that using threads will be faster and less expensive.
Can anyone send me a sample code of how to do this? I'm thinking that I should simply change (1) to a ParameterizedThreadStart... but maybe there's a better practice?
Thanks in advance.
Rafferty