yield是C#为了简化遍历操作实现的语法糖,我们知道如果要要某个类型支持遍历就必须要实现系统接口IEnumerable,这个接口后续实现比较繁琐要写一大堆代码才能支持真正的遍历功能。举例说明 using System;using System.Collections.Generic;using S ...
/// <summary> /// 实体查询 /// </summary> public IEnumerable<TEntity> GetSearchList(System.Linq.Expressions.Expression<Func<TEntity, bool>> where) { if (w ...
分类:
其他好文 时间:
2016-12-17 16:17:46
阅读次数:
242
namespace _03{ class Program { public static void Main() { Person person = new Person(); IEnumerator ienu= person.GetEnumerator(); while (ienu.MoveNex ...
分类:
编程语言 时间:
2016-12-15 11:38:22
阅读次数:
204
1. DataTable读取列表 DataSet ds = new DataSet();// 省略ds的Fill代码DataTable products = ds.Tables["Product"];IEnumerable<DataRow> rows = from p in products.AsE ...
分类:
其他好文 时间:
2016-11-22 17:28:37
阅读次数:
260
所属命名空间:System.Collections.Generic public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable List<T>类是 ArrayList ...
分类:
其他好文 时间:
2016-11-20 18:31:44
阅读次数:
478
public static IEnumerable<T> ToEntityList<T>(this DataTable table) where T : class { var entityList = new List<T>(); if (table != null && table.Rows.C ...
分类:
其他好文 时间:
2016-11-19 12:01:10
阅读次数:
133
IEnumerable接口中的方法是返回IEnumator的对象,集合继承了IEnumerator接口才能实现Foreach方法实现遍历。集合类都继承IEnumable和IEnumerator接口,或者说是这两个接口提供foreach遍历的功能。 综上所述,一个类是否支持foreach遍历,必须满足 ...
分类:
编程语言 时间:
2016-11-15 23:48:19
阅读次数:
1326
GetEnumerator()方法的实质实现: 说明:只要一个集合点出GetEnumerator方法,就获得了迭代器属性,就可以用MoveNext和Current来实现foreach的效果,如上图。 在.NET中,迭代器模式被IEnumerator和IEnumerable及其对应的泛型接口所封装。如 ...
分类:
编程语言 时间:
2016-10-28 02:36:54
阅读次数:
284
Linq是在.Net3.5之后首次引入的,这种查询语言简单易学,可用范围非常广泛在学着之前,一直用在数据库操作之上,但是在学习这节课之后才发现,凡是实现泛型的接口类型都可以使用linq,简单来说就是实现IEnumerable<T>接口。那么什么是泛型?什么是非泛型? 先说说非泛型,是.Net2.0之 ...