使用yield关键字,非常的方便

 private static IEnumerable<Control> GetChildren(Control frmRootDock)
        {
            if (frmRootDock == null)
            {
                throw new ArgumentNullException("");
            }

            var list = new List<Control>();
            foreach (Control item in frmRootDock.Controls)
            {
                foreach (Control c in GetChildren(item))
                {
                    yield return c;
                }
                yield return item;
            }
        }

 

相关文章:

  • 2022-12-23
  • 2022-02-13
  • 2021-12-18
  • 2021-07-16
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-07-25
  • 2022-12-23
  • 2021-12-25
  • 2021-08-14
  • 2021-07-14
  • 2022-12-23
相关资源
相似解决方案