IEnumerable扩展
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扩展的更多相关文章
- 为IEnumerable扩展一个ForEach方法
IEnumerable没有一个ForEach方法,我们可以使用C#写一个扩展方法: Source Code: using System; using System.Collections.Generi ...
- C# DataTable,DataSet,IList,IEnumerable 互转扩展属性
using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.R ...
- 【细语】C#之扩展方法原理及其使用
1.写在前面 今天群里一个小伙伴问了这样一个问题,扩展方法与实例方法的执行顺序是什么样子的,谁先谁后(这个问题会在文章结尾回答).所以写了这边文章,力图从原理角度解释扩展方法及其使用. 以下为主要内容 ...
- 状态机/迭代器/LINQ/协程
状态机 有限状态机(Finite State Machine 或 Finite State Automata)是软件领域中一种重要的工具. 状态机允许一个对象在其内部状态改变时改变它的行为.对象内部状 ...
- .net 温故知新:【6】Linq是什么
1.什么是Linq 关于什么是Linq 我们先看看这段代码. List<int> list = new List<int> { 1, 1, 2, 2, 3, 3, 3, 5, ...
- 为IEnumerable<T>添加RemoveAll<IEnumerable<T>>扩展方法--高性能篇
最近写代码,遇到一个问题,微软基于List<T>自带的方法是public bool Remove(T item);,可是有时候我们可能会用到诸如RemoveAll<IEnumerab ...
- IEnumerable<T>与IQueryable<T>以及.net的扩展方法
首先看看继承关系 public abstract class DbSet : DbQuery public abstract class DbQuery : IOrderedQueryable, IQ ...
- 扩展 IEnumerable<T>,让它根据另一个集合的顺序来排列
假如我有两个集合: public class Teacher { public int Id { get; set; } public string Name { get; set; } } publ ...
- IEnumerable接口的扩展方法
/// <summary>/// IEnumerable接口的扩展方法,支持它的实现类是List的情况/// </summary>using System.Collection ...
随机推荐
- arithmetic-slices
https://leetcode.com/problems/arithmetic-slices/ public class Solution { public int numberOfArithmet ...
- C#接收xmlrpc接口返回哈希表格式
C#在调用xmlrpc接口时返回的是int值就可以直接获取,最近在调用一个接口是获取一个账号记录的详细信息,xmlrpc接口返回的是一个哈希值. 所以直接用int或者Hashtable 来获取返回值执 ...
- unity shader 编译时间过长
去掉opengles2.0能省一半时间 换ssd Compiled shader 'Shader Forge/Scenes_Ground_Standard_M' in 315.51s gles ...
- windows 下apache 以fastcgi形式执行php
以xampp为例解说,过程例如以下: 1:下载相应的mod_fastcgi .下载參考站点:http://www.apachelounge.com/download/VC11/ 2:拷贝mod_fas ...
- C# 继承实现父类方法、重写、重载
继承是派生类(子类)去实现(重写<override>.重构<new>)基类(父类)的方法或属性.从而获取在派生类中要实现的功能. 子类调用父类构造方法,在父类中有个实现姓名和年 ...
- PHP #2003 - 服务器没有响应怎么办
1 出现这个问题的时候,首先可以肯定Apache服务器没有问题,因为如果Apache服务器有问题,则根本登不上phpMyadmin,如果你能登上localhost则说明Apache服务器没问题. 2 ...
- Android 文件存储 和 权限管理
转载请标明出处: :http://blog.csdn.net/huaiyiheyuan/article/details/52473984 android SD卡主要有两种存储方式 Internal . ...
- struts2 ValueStack的作用
Value Stack的作用: 1. 可以作为一个数据中转站 2. 用于在前台-后台之间传递数据,最典型的做法就是struts2标签也ognl表达式的结合.我用得最多的就是数据 ...
- Tomcat日志、项目中的log4j日志、控制台——我的日志最后到底跑哪去了?
1.Tomcat自带日志功能,即时你的项目中有log4j也不会影响到Tomcat自己记录日志. 2.你的项目中的log4j中的日志指定打印到什么地方(控制台或者文件),便会打印到什么地方,和Tomat ...
- vpngate 的使用
第一次为小日本打广告.. .我仅仅想仰天大喊..玛的戈壁. .. 竟然活到这个份上了...想出去看看的往下看.. vpngate 下载: http://pan.baidu.com/s/1hq5x3Ly ...