请问从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;
}
}