Maybe I couldn't explain well, but this should explain: I have a int field called getParentNode(TreeNode) to get how many parent it has (e.g if there is 2 nodes below node, count will be 2) And I have a List field called getParentNames(TreeNode) that returns all of the parent's names.
getParentCount:
int getParentCount(TreeNode node)
{
int count = 1;
while (node.Parent != null)
{
count++;
node = node.Parent;
}
return count;
}
getParentsNames:
List<string> getParentNames(TreeNode node)
{
List<string> list = new List<string>();
for (int i = 0; i < getParentCount(node); i++)
{
//i = 1 : list.Add(node.Parent.Text);
//i = 2 : list.Add(node.Parent.Parent.Text);
//i = 3 ...
}
return list;
}
Do I need to check if (i == 0) (I don't want to write manually because number can be anything) or something? Regards.