//使用Yield计算Fibonacci数列 publiclong Fib_Yield(int n) ...{ long num =0; int index =3; foreach (long b inthis.Yield(1, 1)) ...{ if (index == n) ...{ num = b; break; } else ++index; } return num; } public IEnumerable<long> Yield(long b1, long b2) ...{ yieldreturn b1 + b2; foreach (long b in Yield(b2, b1 + b2)) yieldreturn b; }
public IEnumerable<Control> Iterator(Control baseCtl, Tuple t) ...{ foreach(Control c in baseCtl.Controls) ...{ if (!t.HasType(c)) ...{ foreach (Control c1 in Iterator(c, t)) yieldreturn c1; }
else //07.12.24加 yieldreturn c; } } publicvoid SetValue(EntityObject obj) ...{ foreach(Control c in Iterator(this, new Tuple<TextBox, CheckBox, Button>())) ...{ //操作c } }