tags:

views:

186

answers:

1

When i hit the assert i was surprise bc i expected my implementation to be correct. It should work but didnt so i wrote the code below and comment out the assert and find. Why does my code work and find does not?

            var z = n.Find(v[i], false);
            //Debug.Assert(z.Count() == 1);
            //n = z[0].Nodes;
            if (z.Count() != 1)//count == 0
            {
                for (int ii = 0; ii < n.Count; ii++)
                {
                    if (n[ii].Text == v[i])
                    {
                        n = n[ii].Nodes;
                        break;
                    }
                }
            }
+1  A: 

Find() method takes key (not a value).

   TreeNode root = new TreeNode("root");

            TreeNode t1 = new TreeNode();
            t1.Nodes.Add("A","A1");
            t1.Nodes.Add("B","B2");
            t1.Nodes.Add("C","C3");
            root.Nodes.Add(t1);
            TreeNodeCollection tc = root.Nodes;
            var tt = tc.Find("A",true  );
adatapost