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. ArcGIS教程:加权叠加

    摘要 使用经常使用測量比例叠加多个栅格数据,并依据各栅格数据的重要性分配权重. 插图 插图中,两个输入栅格已又一次分类为 1 至 3 三种公共測量级别.为每一个栅格均分配了一个影响百分比.这些像元值与 ...

  2. SQL Server查询所有的表名/空间占用量/行数

    select object_name(id) tablename, 8*reserved/1024 reserved, rtrim(8*dpages)+'kb' used, 8*(reserved-d ...

  3. C如何获取文件夹下所有文件

    http://baike.baidu.com/view/1186290.htm?fr=aladdin 使用io.h中的_findfirst,_findnext,_findclose,_finddata ...

  4. ADO.Net的小知识(连接数据库)二

    上次提到数据库连接有两种形式断开式连接和打开式连接,断开式连接我已经讲解了,下面我来给大家讲解一下打开式连接 (1)引入命名空间:using System.Data.SqlClient; 该语句用于导 ...

  5. ListVIew中插入view

    public class MainActivity extends Activity { private ListView listview; private List<String> d ...

  6. iOS实用的小技巧

    1.快捷键 上传APP模拟器截图:comm+s 自动保存到桌面 2.storyboard 改型号尺寸 如从iPad改为iPhone6:

  7. 各I/O模型 对应Web服务应用模型(select,poll,epoll,kevent,"/dev/poll")

    一.利用select多路复用I/O的Web服务应用模型  /* 可读.可写.异常三种文件描述符集的申明和初始化.*/ fd_set readfds, writefds, exceptionfds; F ...

  8. 修改UILabel的行间距

    在iOS开发中  有时候为了调整一些UI效果  我们需要调整UILabel之间的行间距: contentLabel.text:label上显示的文字内容; 5:label行间距; contentLab ...

  9. 【转】Centos配置yum源

    转载自:http://blog.chinaunix.net/uid-23683795-id-3477603.html 网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的 ...

  10. Ubuntu 安装php mcrypt

    sudo apt-get install php5-mcrypt libmcrypt4 libmcrypt-dev sudo php5enmod mcrypt sudo /etc/init.d/apa ...