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";
}
}
Ienumerable和Ienumerator的使用的更多相关文章
- 细说 C# 中的 IEnumerable和IEnumerator接口
我们先思考几个问题: 为什么在foreach中不能修改item的值? 要实现foreach需要满足什么条件? 为什么Linq to Object中要返回IEnumerable? 接下来,先开始我们的正 ...
- 迭代器学习之一:使用IEnumerable和IEnumerator接口
写博客是检验我学习的成果之一以及自我总结的一种方式,以后会经常利用这种方式进行技术交流和自我总结,其中认识不深难免会有错误,但是一直懂得不懂就问,不懂就学的道理! 1.首先看一个简单的列子 , , , ...
- C# ~ 从 IEnumerable / IEnumerator 到 IEnumerable<T> / IEnumerator<T> 到 yield
IEnumerable / IEnumerator 首先,IEnumerable / IEnumerator 接口定义如下: public interface IEnumerable /// 可枚举接 ...
- IEnumerable和IEnumerator
概述 IEnumerable和IEnumerator接口存在的意义:用来实现迭代的功能! public interface IEnumerable { IEnumerator GetEnumerato ...
- 关于迭代器中IEnumerable与IEnumerator的区别
首先是IEnumerable与IEnumerator的定义: 1.IEnumerable接口允许使用foreach循环,包含GetEnumerator()方法,可以迭代集合中的项. 2.IEnumer ...
- IEnumerable和IEnumerator 详解 (转)
原文链接:http://blog.csdn.net/byondocean/article/details/6871881 参考链接:http://www.cnblogs.com/hsapphire/a ...
- C#基础知识系列九(对IEnumerable和IEnumerator接口的糊涂认识)
前言 IEnumerable.IEnumerator到现在为止对这两个接口还是不太理解,不理解但是自己总是想着试着要搞明白,毕竟自己用的少,所以在此先记录一下.以备自己日后可以来翻查,同时也希望园子里 ...
- [转]那些年我还不懂:IList,ICollection,IEnumerable,IEnumerator,IQueryable
1.首先看一个简单的例子 int[] myArray = { 1, 32, 43, 343 }; IEnumerator myie = myArray.GetEnumerator(); myie.Re ...
- 转载IEnumerable与IEnumerator区别
public interface IEnumerable { IEnumerator GetEnumerator(); } public interface IEnumerator { ...
- IEnumerable、IEnumerator与yield的学习
我们知道数组对象可以使用foreach迭代进行遍历,同时我们发现类ArrayList和List也可以使用foreach进行迭代.如果我们自己编写的类也需要使用foreach进行迭代时该怎么办呢? IE ...
随机推荐
- A Simple Problem with Integers BZOJ3212 线段树
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...
- Java技术列表
完整的java技术列表,可以在oracle官网找到: https://www.oracle.com/technetwork/java/javaee/tech/index.html JSR: Java ...
- 整合feign过程中出现问题:
一:编译器报错 这个地方是由于没有被spring管理,编译器报错,可以选择加上@comoponent这个注解 也可以选择不加,启动程序是不会报错的. 二 报错为空: org.springframewo ...
- java修饰符的一些知识点
1.java默认的修饰符是不加任何标志,默认为包修饰符,在同一个包下的类都可以对其进行调用.若需要进行跨包调用,往往需要加上修饰符public2.public修饰符对需要调用其的消费者都是可见的,一个 ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1001
Problem A Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键
google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...
- 如何 将下载离线 nupkg 文件 安装到VS2017
https://www.cnblogs.com/cncc/articles/8276878.html --------------------------------------------- ...
- uva 442
#include<iostream>#include<stack>#include<map>using namespace std;struct node{ int ...
- css 断行省略号,隐藏,fixed定位
text-overflow(clip | elipsis)(显示省略号| 不显示省略号) white-space:nowrap 强制文字不断行 word-break:break-all; ...
- socket阻塞与非阻塞情况下的recv、send、read、write返回值 以及epool_wait返回值学习
https://www.cnblogs.com/longingforlife/p/3289976.html