日期:2014-05-16  浏览次数:20847 次

请问从foreach循环中直接return有风险吗
请问

        private bool entryexist(string defaultNamingContext)
        {

            int i = 0;
            bool result = false;
            //find all nodes in treeview_ad
            TreeNode[] arr = treeView_ad.Nodes.Find("", true);
            foreach (TreeNode tn in arr)
            {
                if (tn.Text == defaultNamingContext)
                {
                    i++;
                }
            }
            if (i > 0)
            {
                result = true;
            }
            if (i == 0)
            {
                result = false;
            }
            return result;
        }




        private bool entryexist(string defaultNamingContext)
        {

            int i = 0;
            bool result = false;
            //find all nodes in treeview_ad
            TreeNode[] arr = treeView_ad.Nodes.Find("", true);
            foreach (TreeNode tn in arr)
            {
                if (tn.Text == defaultNamingContext)
                {
                    return true;
                }
            }