• 【Unity3D/C#】利用IEnumerable<>和yield产生斐波那契数列


    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;
            }
        }
    }
  • 相关阅读:
    协成
    进程与线程-多线程
    进程与线程2
    进程与线程
    socket编程
    常用模块二(hashlib、configparser、logging)
    异常处理
    python之路——面向对象进阶
    封装
    初识——面向对象
  • 原文地址:https://www.cnblogs.com/qiuxiangmuyu/p/5837627.html
Copyright © 2020-2023  润新知