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. [AngularJS] Catching errors with $exceptionHandler

    The AngularJS $exceptionHandler service allows you to catch and handle unanticipated JavaScript erro ...

  2. SAP交货单过账自动生产采购订单、采购订单自动收货入库

    公司间需要买卖操作,由于发货和收货都是同一批人在操作,为了减少业务人员的工作量,提高工作效率,特实现以上功能 1.增强实现:增强点为交货单过账成功时触发,在提交前触发,如果遇到不可预知问题,可能造成数 ...

  3. 学习笔记之Linux开发(C语言)

    第二章 Linux下C程序开发环境 vi编辑器 gcc 第三章 Linux基础 Kernel Shell 第三章 Linux技术实验 ls -l 以长格式的形式查看当前目录下所有可见文件的详细属性. ...

  4. 梭子鱼:APT攻击是一盘更大的棋吗?

    随着企业对IT的依赖越来越强,APT攻击可能会成为一种恶意打击竞争对手的手段.目前,APT攻击目标主要有政治和经济目的两大类.而出于经济目的而进行的APT攻击可以获取竞争对手的商业信息,也可使用竞争对 ...

  5. check_area

    CCTouch* pTouch = ...; CCSprite* pSprite = ...; CCRect rect = pSprite ->boundingBox(); if ((& ...

  6. PowerDesigner 根据NAME属性自动生成表和列注释(不用写脚本)

    PowerDesigner 11 menu: [Database]->[Database Generation] tab: [Tables & Views]->check tabl ...

  7. SQL Server 内存管理

    windows memory:  Memory: Cache Bytes 是系统的working set, 也就是系统使用的物理内存数目. 可以观察Windows用了多少物理内存. 1. System ...

  8. mysql:通用查询日志general_log

    1.通用查询日志:记录建立的客户端连接和执行的语句,通用查询日志默认情况下不是开启的,通用查询日志是以文本方式存放的 当需要采样分析的时候手工开启: SET Global general_log=1; ...

  9. LNMP一键安装包-CentOS 5/6下自动编译安装Nginx,MySQL,PHP

    适用环境: 系统支持:CentOS-5 (32bit/64bit).CentOS-6 (32bit/64bit) 内存要求:≥128M 安装了什么: 1.Nginx-1.2.0 2.MySQL 5.5 ...

  10. 【模拟】UVa 1030 - Image Is Everything

    1030 - Image Is Everything Time limit: 3.000 seconds Your new company is building a robot that can h ...