C# 方法里引用自身方法是怎么个情况?

zmidl 2014-04-17 08:45:56
比如
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);
}
}
}
...全文
621 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 4 楼 zmidl 的回复:
讲递归我不知道,讲循环我明白。
zmidl 2014-04-30
  • 打赏
  • 举报
回复
讲递归我不知道,讲循环我明白。
  • 打赏
  • 举报
回复
递归调用。。。。。确保一定有停止点,其实其本质就像for,while之类的循环
threenewbee 2014-04-17
  • 打赏
  • 举报
回复
递归都没见过。
h82258652 2014-04-17
  • 打赏
  • 举报
回复
有什么出奇的,就是递归调用而已。

110,525

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧