zoukankan      html  css  js  c++  java
  • Ienumerable和Ienumerator的使用

    using UnityEngine;
    using System.Collections;
    
    public class TestCoroutine : MonoBehaviour {
    	void Start () {
    		StartCoroutine (test());
    		print ("_______________________________");
    		TestIenumerator ();
    		print ("_______________________________");
    		TestIenumerable();
    		print ("_______________________________");
    	}
    	void TestIenumerable(){
    		IEnumerable t = a ();
    		IEnumerator tp = t.GetEnumerator ();
    		foreach(string k in t){
    			print (k);
    		}
    	}
    	void TestIenumerator(){
    		IEnumerator e = YieldSomeStuff();
    		while(e.MoveNext())
    		{
    			print(string.Format("while: {0}",e.Current));
    		}
    	}
    	IEnumerator test(){
    		print ("test");
    //		yield break;
    		yield return new WaitForSeconds(1);
    		print ("test2");
    	}
    	IEnumerator YieldSomeStuff()
    	{
    		yield return new WaitForSeconds (1);
    		print ("____________");
    		yield return "hello";
    		print ("____________");
    		yield return "world";
    		print ("____________");
    	}
    	IEnumerable a(){
    		yield return "Tests";
    		yield return "Tests";
    		yield return "Tests";
    	}
    }
    

      

  • 相关阅读:
    hdoj 1010-Tempter of the Bone
    leetcode 91. 解码方法
    leetcode 925. 长按键入
    leetcode 437. 路径总和 III
    leetcode 892. 三维形体的表面积
    二分查找
    HBASE 安装
    Linux 日常指令
    Linux Centos7 配置代理
    Linux ssh 免密
  • 原文地址:https://www.cnblogs.com/mttnor/p/6061730.html
Copyright © 2011-2022 走看看