void Main()
{
// This uses a custom 'Pair' extension method, defined below. Customers
.Select (c => c.Name.ToUpper())
.Pair() // Local from this point on.
.OrderBy (n => n)
.Dump(); // Here's a more substantial example: Customers
.Select (c => c.Name.ToUpper())
.OrderBy (n => n)
.Pair() // Local from this p.oint on.
.Select ((n, i) => "Pair " + i.ToString() + " = " + n)
.Dump(); Customers.Select (c => c.Name.ToUpper()).Add().Dump();
} public static class MyExtensions
{
public static IEnumerable<string> Pair (this IEnumerable<string> source)
{
string firstHalf = null;
foreach (string element in source)
if (firstHalf == null)
firstHalf = element;
else
{
yield return firstHalf + ", " + element;
firstHalf = null;
}
} public static IEnumerable<string> Add (this IEnumerable<string> source)
{
int index=;
foreach (string element in source)
{
yield return "NO."+index+++" " + element;
} }
}

IEnumerable扩展的更多相关文章

  1. 为IEnumerable扩展一个ForEach方法

    IEnumerable没有一个ForEach方法,我们可以使用C#写一个扩展方法: Source Code: using System; using System.Collections.Generi ...

  2. C# DataTable,DataSet,IList,IEnumerable 互转扩展属性

    using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.R ...

  3. 【细语】C#之扩展方法原理及其使用

    1.写在前面 今天群里一个小伙伴问了这样一个问题,扩展方法与实例方法的执行顺序是什么样子的,谁先谁后(这个问题会在文章结尾回答).所以写了这边文章,力图从原理角度解释扩展方法及其使用. 以下为主要内容 ...

  4. 状态机/迭代器/LINQ/协程

    状态机 有限状态机(Finite State Machine 或 Finite State Automata)是软件领域中一种重要的工具. 状态机允许一个对象在其内部状态改变时改变它的行为.对象内部状 ...

  5. .net 温故知新:【6】Linq是什么

    1.什么是Linq 关于什么是Linq 我们先看看这段代码. List<int> list = new List<int> { 1, 1, 2, 2, 3, 3, 3, 5, ...

  6. 为IEnumerable<T>添加RemoveAll<IEnumerable<T>>扩展方法--高性能篇

    最近写代码,遇到一个问题,微软基于List<T>自带的方法是public bool Remove(T item);,可是有时候我们可能会用到诸如RemoveAll<IEnumerab ...

  7. IEnumerable<T>与IQueryable<T>以及.net的扩展方法

    首先看看继承关系 public abstract class DbSet : DbQuery public abstract class DbQuery : IOrderedQueryable, IQ ...

  8. 扩展 IEnumerable<T>,让它根据另一个集合的顺序来排列

    假如我有两个集合: public class Teacher { public int Id { get; set; } public string Name { get; set; } } publ ...

  9. IEnumerable接口的扩展方法

    /// <summary>/// IEnumerable接口的扩展方法,支持它的实现类是List的情况/// </summary>using System.Collection ...

随机推荐

  1. daemon函数的原理及使用详解

    在linux系统下创建守护进程的原理及步骤在文章(链接如下)中介绍过.http://blog168.chinaunix.net/space.php?uid=20196318&do=blog&a ...

  2. go语言基础之常量

    1.常量 示例: package main //必须有一个main包 import "fmt" func main() { //变量:程序运行期间,可以改变的量, 变量声明需要va ...

  3. C#程序输出信息到调试窗口的几种方式

    网站项目: System.Diagnostics.Debug.WriteLine("aaa"); 控制项目:Console.WriteLine("bbb"); ...

  4. Parallax Occlusion Mapping in GLSL [转]

    http://www.sunandblackcat.com/tipFullView.php?topicid=28   This lesson shows how to implement differ ...

  5. TestNG 一、 概论

    一. 概论         TestNG,即Testing, NextGeneration,下一代测试技术,是一套根据JUnit 和NUnit思想而构建的利用注释来强化测试功能的一个测试框架,即可以用 ...

  6. Less is better than never

    很多时候,在正确的做一件事之前,我们总会尝试一些笨办法或者白费一些力气: 很多时候,即使在正确的做一件事,由于这事情并非一日之功,而没有收到立竿见影的效果: 之后,我们的内心便容易动摇,怀疑,甚至想要 ...

  7. 《大话操作系统——做坚实的project实践派》(5)

    有人说我不是仅仅会玩X86吗?我如今铁板钉钉的申明:我事实上兼通:ARM.IA-32.IA-32e.AMD64. ​了解MIPS.但没做过MIPS由于确实没有对应的MIPS硬件平台. ​

  8. vue - webpack.dev.conf.js for CopyWebpackPlugin

    描述:将单个文件或整个目录复制到构建目录 官网地址:https://www.npmjs.com/package/copy-webpack-plugin // 复制到自定义静态源 new CopyWeb ...

  9. JQUERY插件学习之jQuery UI

    jQuery UI:http://jqueryui.com/ jQuery UI介绍: jQuery UI 是以 jQuery 为基础的开源 JavaScript 网页用户界面代码库.包含底层用户交互 ...

  10. WebDriver API——第3部分Action Chains

    The ActionChains implementation, class selenium.webdriver.common.action_chains.ActionChains(driver) ...