【原】yield的最基本用法
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace Itcast.Mall.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string[] strs = new string[] { "", "", "" };
IEnumerable<int> ints = GetInts(strs);
foreach (var item in ints)
{
//测试,当item的值大于1后,下面GetInts里的foreach只会执行到这个对应的值,后面的就冻结,不执行了,节约资源;
if (item > )
{
break;
}
Console.WriteLine(item);
}
Console.ReadKey();
}
static IEnumerable<int> GetInts(string[] strs)
{
foreach (var item in strs)
{
Console.WriteLine(item.GetType());
yield return Convert.ToInt32(item);
}
}
}
}
【原】yield的最基本用法的更多相关文章
- scala语言yield配合for的用法实例
yield配合for的用法 话不多说见实例 package com.donews.reynold /** * Created by reynold on 2017/3/23. */ object Sc ...
- yield self和instance_eval用法区别
class Foo def initialize(&block) instance_eval(&block) if block_given? end end class Foo def ...
- 【原】Arrays.binarySearch() 的用法
Arrays.binarySearch() 的用法 1.binarySearch(Object[] a, Object key) Searches the specified array for th ...
- 你能说出多线程中sleep、yield、join的用法及sleep与wait区别?
Object中的wait.notify.notifyAll,可以用于线程间的通信,核心原理为借助于监视器的入口集与等待集逻辑 通过这三个方法完成线程在指定锁(监视器)上的等待与唤醒,这三个方法是以锁( ...
- java多线程系类:JUC原子类:03之AtomicLongArray原子类
概要 AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray这3个数组类型的原子类的原理和用法相似.本章以AtomicLongArray对数 ...
- Python yield 使用浅析
转载来自: http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ 初学 Python 的开发者经常会发现很多 Pyth ...
- Java多线程系列--“JUC原子类”02之 AtomicLong原子类
概要 AtomicInteger, AtomicLong和AtomicBoolean这3个基本类型的原子类的原理和用法相似.本章以AtomicLong对基本类型的原子类进行介绍.内容包括:Atomic ...
- Java多线程系列--“JUC原子类”03之 AtomicLongArray原子类
概要 AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray这3个数组类型的原子类的原理和用法相似.本章以AtomicLongArray对数 ...
- java多线程系类:JUC原子类:02之AtomicLog原子类
概要 AtomicInteger, AtomicLong和AtomicBoolean这3个基本类型的原子类的原理和用法相似.本章以AtomicLong对基本类型的原子类进行介绍.内容包括:Atomic ...
随机推荐
- 【剑指Offer学习】【全部面试题汇总】
剑指Offer学习 剑指Offer这本书已经学习完了.从中也学习到了不少的东西,如今做一个总的文件夹.供自已和大家一起參考.学如逆水行舟.不进则退.仅仅有不断地学习才干跟上时候.跟得上技术的潮流! 全 ...
- PHP PDO函数库具体解释
文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/565 PDO是一个"数据库訪问抽象层",作用是统一各种数据库的訪问接口 ...
- select poll使用
select poll使用 2.1. 怎样管理多个连接?“我想同一时候监控一个以上的文件描写叙述符(fd)/连接(connection)/流(stream),应该怎么办?” 使用 select ...
- Opencv cvCircle函数
cvCircle(CvArr* img, CvPoint center, int radius, CvScalar color, int thickness=1, int lineType=8, in ...
- compile ffmpeg
download SDL 1.2.xxx version source code. 1) configure 2) make & make instll download recent ffm ...
- mapping 详解1(mapping type)
映射(mapping) 映射是定义一个文档以及其所包含的字段如何被存储和索引的方法. 例如,用映射来定义以下内容: 哪些 string 类型的 field 应当被当成当成 full-text 字段 哪 ...
- Java队列实现
队列数组实现:队列长度有限,但是考虑到平时一般都使用有界队列,这应该也不算是个缺点 public class Queue { private Object[] objs; private int he ...
- scala学习笔记:理解类继承
scala> import scala.reflect._ import scala.reflect._ scala> class Person(@BeanProperty var nam ...
- linux gpg 使用笔记
http://linux.chinaunix.net/techdoc/system/2009/04/30/1109541.shtml 一.GnuPG的简介 我们在网上的发送的邮件是明文的,可以 ...
- TFS2013 安装出现TF400102错误解决
我是参照:http://www.cnblogs.com/zhibincai/archive/2013/11/25/3442285.html 进行安装的windows 2012 + sql 2012 S ...