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的最基本用法的更多相关文章

  1. scala语言yield配合for的用法实例

    yield配合for的用法 话不多说见实例 package com.donews.reynold /** * Created by reynold on 2017/3/23. */ object Sc ...

  2. yield self和instance_eval用法区别

    class Foo def initialize(&block) instance_eval(&block) if block_given? end end class Foo def ...

  3. 【原】Arrays.binarySearch() 的用法

    Arrays.binarySearch() 的用法 1.binarySearch(Object[] a, Object key) Searches the specified array for th ...

  4. 你能说出多线程中sleep、yield、join的用法及sleep与wait区别?

    Object中的wait.notify.notifyAll,可以用于线程间的通信,核心原理为借助于监视器的入口集与等待集逻辑 通过这三个方法完成线程在指定锁(监视器)上的等待与唤醒,这三个方法是以锁( ...

  5. java多线程系类:JUC原子类:03之AtomicLongArray原子类

    概要 AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray这3个数组类型的原子类的原理和用法相似.本章以AtomicLongArray对数 ...

  6. Python yield 使用浅析

    转载来自: http://www.ibm.com/developerworks/cn/opensource/os-cn-python-yield/ 初学 Python 的开发者经常会发现很多 Pyth ...

  7. Java多线程系列--“JUC原子类”02之 AtomicLong原子类

    概要 AtomicInteger, AtomicLong和AtomicBoolean这3个基本类型的原子类的原理和用法相似.本章以AtomicLong对基本类型的原子类进行介绍.内容包括:Atomic ...

  8. Java多线程系列--“JUC原子类”03之 AtomicLongArray原子类

    概要 AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray这3个数组类型的原子类的原理和用法相似.本章以AtomicLongArray对数 ...

  9. java多线程系类:JUC原子类:02之AtomicLog原子类

    概要 AtomicInteger, AtomicLong和AtomicBoolean这3个基本类型的原子类的原理和用法相似.本章以AtomicLong对基本类型的原子类进行介绍.内容包括:Atomic ...

随机推荐

  1. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  2. Xposed知识

    最近闹得沸沸扬扬的MIUI抄袭Xposed不署名事件,为此在这里普及一下相关的Xposed的知识. 相关资源 source code: https://github.com/rovo89 online ...

  3. Firefly distributed模块的原理与twisted中PB远程调用协议

    这些天断断续续在看Firefly, 看了一下distributed模块的设计,其实就是使用的twisted.spread.pb觉得以后要是想用Firefly有必要了解一下twisted, 所以在网上查 ...

  4. C++类的定义之作用域

    每个类都定义了自己的新作用域和唯一的类型.在类的定义体内声明内成员,将成员名引入类的作用域.两个不同的类具有两个不同的类作用域. 例如: Class First { int memi; double  ...

  5. 详解 MySQL 中的 explain

    来源:persister 链接:http://www.blogjava.net/persister/archive/2008/10/27/236813.html 在 explain的帮助下,您就知道什 ...

  6. perl dtrace2

    http://search.cpan.org/~chrisa/Devel-DTrace-Provider-1.11/lib/Devel/DTrace/Provider.pm

  7. global 用法

    <?php//$GLOBALS['he']="hechunhuae";function Test(){ //global $he; $GLOBALS['he']=" ...

  8. 【转】int const A::func()和int A::func() const

    int const A::func() { return 0; }int A::func() const { return 0; } 上面的代码是合法的,其中A::func成员函数[只能在成员函数后面 ...

  9. iOS-制作Framework

    步骤 打开Xcode,创建新工程.手下留情,请先看图! 在TARGETS下选中工程,在Build Settings下更改几个参数. 更改参数 在Architectures下增加armv7s,并选中.将 ...

  10. SQL 学习与工作日常:语句积累

    1.跨服务器连接数据表 --打开服务器配置'Ad Hoc Distributed Queries' --exec sp_configure 'show advanced options',1 --re ...