标签:
using UnityEngine; using System.Collections; using System.Collections.Generic; public class YieldTest : MonoBehaviour { public bool b = true; public IEnumerator myIEnumertor = null; void Awake() { } // Use this for initialization void Start () { myIEnumertor = GenerateFibonacci().GetEnumerator(); int i = 0; do { myIEnumertor.MoveNext(); Debug.Log(myIEnumertor.Current); i++; } while (i < 10); } // Update is called once per frame void Update () { } public static IEnumerable<int> GenerateFibonacci() { yield return 0; yield return 1; int last0 = 0, last1 = 1, current; while (true) { current = last0 + last1; yield return current; last0 = last1; last1 = current; } } }
【Unity3D/C#】利用IEnumerable<>和yield产生斐波那契数列
标签:
原文地址:http://www.cnblogs.com/qiuxiangmuyu/p/5837627.html