yield return只是起到一个枚举的作用,记录此次的返回值,跳到下一步返回值........
public partial class ViewSource : Window
{
int[] nums = new int[4] { 1, 2, 3, 4 };
public ViewSource()
{
InitializeComponent();
SetText();
}
public IEnumerable Reverse()
{
for (int i = 3; i >= 0; i--)
{
yield return nums[i];
}
}
public void SetText()
{
foreach (int item in Reverse())
{
txtBlock.Text += item.ToString();
}
}
}