行一恒  

  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();
                                        
            }
        }
    }

posted on 2013-11-26 09:49  行一恒  阅读(121)  评论(0编辑  收藏  举报