C# 方法里引用自身方法是如何个情况
C# 方法里引用自身方法是怎么个情况?
比如
private void aa(_class obj)
{
.....
.....
this.aa(....);
}
自己调用自己 我从来没见过 但是 编译通过 而且可以运行
这样的 我玩WPF 需要遍历窗体下指定的控件,以前winform的方法自然不能用了,于是我百度了相关代码 ,贴出来
private void SetNotEditable(UIElementCollection uiControls)
{
foreach (UIElement element in uiControls)
{
if (element is TextBox)
{
(element as TextBox).IsEnabled = false;
}
else if (element is Grid)
{
this.SetNotEditable((element as Grid).Children);
}
else if (element is Expander)
{
if ((element as Expander).Content is StackPanel)
{
StackPanel sa = (element as Expander).Content as StackPanel;
this.SetNotEditable(sa.Children);
}
else if ((element as Expander).Content is Grid)
{
Grid sa = (element as Expander).Content as Grid;
this.SetNotEditable(sa.Children);
}
}
else if (element is StackPanel)
{
this.SetNotEditable((element as StackPanel).Children);
}
else if (element is ScrollViewer)
{
StackPanel sp = (element as ScrollViewer).Content as StackPanel;
this.SetNotEditable(sp.Children);
}
}
}
------解决方案--------------------
有什么出奇的,就是递归调用而已。
------解决方案--------------------
递归都没见过。
------解决方案--------------------
递归调用。。。。。确保一定有停止点,其实其本质就像for,while之类的循环
比如
private void aa(_class obj)
{
.....
.....
this.aa(....);
}
自己调用自己 我从来没见过 但是 编译通过 而且可以运行
这样的 我玩WPF 需要遍历窗体下指定的控件,以前winform的方法自然不能用了,于是我百度了相关代码 ,贴出来
private void SetNotEditable(UIElementCollection uiControls)
{
foreach (UIElement element in uiControls)
{
if (element is TextBox)
{
(element as TextBox).IsEnabled = false;
}
else if (element is Grid)
{
this.SetNotEditable((element as Grid).Children);
}
else if (element is Expander)
{
if ((element as Expander).Content is StackPanel)
{
StackPanel sa = (element as Expander).Content as StackPanel;
this.SetNotEditable(sa.Children);
}
else if ((element as Expander).Content is Grid)
{
Grid sa = (element as Expander).Content as Grid;
this.SetNotEditable(sa.Children);
}
}
else if (element is StackPanel)
{
this.SetNotEditable((element as StackPanel).Children);
}
else if (element is ScrollViewer)
{
StackPanel sp = (element as ScrollViewer).Content as StackPanel;
this.SetNotEditable(sp.Children);
}
}
}
------解决方案--------------------
有什么出奇的,就是递归调用而已。
------解决方案--------------------
递归都没见过。
------解决方案--------------------
递归调用。。。。。确保一定有停止点,其实其本质就像for,while之类的循环