Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have code as below and want to implement Linq for time optimization.
C#
if (RadTreeViewCustodian.Nodes[0] != null)
          {
              var node = "";
              for (int i = 0; i < RadTreeViewCustodian.Nodes[0].Nodes.Count; i++)
              {
                  if (RadTreeViewCustodian.Nodes[0].Nodes[i].Text != null)
                  {
                      node =
                          RadTreeViewCustodian.FindNodeByText(RadTreeViewCustodian.Nodes[0].Nodes[i].Text).ToString();
                  }
                  else
                  {
                      node =
                          RadTreeViewCustodian.FindNodeByValue(RadTreeViewCustodian.Nodes[0].Nodes[i].Value)
                                              .ToString();
                  }
                  if (RadTreeViewCustodian.Nodes[0].Nodes[i].Checked == true)
                  {
                      RadTreeViewCustodian.Nodes[0].Nodes[i].Checked = false;

                  }
                  else
                  {
                      RadTreeViewCustodian.Nodes[0].Nodes[i].Checked = true;
                  }
              }
          }



Please help
Posted

1 solution

LINQ is a compiler feature. It has nothing to do to processing time. Of course it would be quicker if your iteration logic is not proper.

Now in your code,

1. Why do you even do this?

C#
if (RadTreeViewCustodian.Nodes[0].Nodes[i].Text != null)
                 {
                     node =
                         RadTreeViewCustodian.FindNodeByText(RadTreeViewCustodian.Nodes[0].Nodes[i].Text).ToString();
                 }
                 else
                 {
                     node =
                         RadTreeViewCustodian.FindNodeByValue(RadTreeViewCustodian.Nodes[0].Nodes[i].Value)
                                             .ToString();
                 }

You already have a node object and you are again finding it in the collection. Not required.

2. This is also not accurate.

C#
if (RadTreeViewCustodian.Nodes[0].Nodes[i].Checked == true)
                  {
                      RadTreeViewCustodian.Nodes[0].Nodes[i].Checked = false;

                  }
                  else
                  {
                      RadTreeViewCustodian.Nodes[0].Nodes[i].Checked = true;
                  }


You just need the if block here and not the else.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900