LINQ查询方法一共提供了两种扩展方法,在System.Linq命名空间下,有两个静态类:Enumerable类,它针对继承了IEnumerable接口的集合进行扩展;Queryable类,针对继承了IQueryable接口的集合进行扩展。我们会发现接口IQueryable实际也是继承了IEnume...
分类:
其他好文 时间:
2014-08-22 17:45:19
阅读次数:
316
由于在MVC中经常会使用到@Html.DropDownList方法,而该方法接收的是List 参数,因此就想着写一个扩展方法,直接把IEnumerable转换为List类型,这样使用起来会比较方便正式进入正文。1、首先创建下面实体: //水果类 public class Fruit { ...
分类:
Web程序 时间:
2014-08-21 14:38:54
阅读次数:
252
一般来说当我们创建自定义集合的时候为了让其能支持foreach遍历,就只能让其实现IEnumerable接口(可能还要实现IEnumerator接口)但是我们也可以通过使用yield关键字构建的迭代器方法来实现foreach的遍历,且自定义的集合不用实现IEnumerable接口注:虽然不用实现I....
分类:
其他好文 时间:
2014-08-15 14:33:18
阅读次数:
202
varN=20;varlist=Enumerable.Range(0,N).ToArray();N=list.ForEach(n=>list[n]=n<2?n:list[n-1]+list[n-2]).Last();
分类:
其他好文 时间:
2014-08-04 13:58:27
阅读次数:
188
??
public IEnumerable ReportView_List(VMB_ReportConditions requiredModel)
{
IEnumerable resultModel = new List();
IQueryable merchantList;
...
分类:
数据库 时间:
2014-07-30 17:42:44
阅读次数:
307
今天用EF写东西玩,觉得IEnumerable里面除了where()、select(),是不是能添加点其他方法呢。 想做就做,F12到方法定义: public static IEnumerable Where(this IEnumerable source, Func predicate)...
分类:
其他好文 时间:
2014-07-29 14:14:38
阅读次数:
213
//实现IEnumerable接口中的GetEnumerator()方法,为了能支持foreach遍历 class MyClass:IEnumerable { List list = new List(); private List items; public List Items { get { ...
分类:
其他好文 时间:
2014-07-27 23:27:49
阅读次数:
308
=================================================简单的实现IEnumerable接口------------------------------------Person.csusingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Collections;
na..
分类:
其他好文 时间:
2014-07-25 11:36:32
阅读次数:
200
通过一个例子来看-------------------------------------------------------Student.csusingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
usingSystem.Collections;
namespaceConsoleApplication6
{
publiccla..
分类:
其他好文 时间:
2014-07-25 11:36:22
阅读次数:
214
在上一篇文章中,说了下foreach的用法,但是还是比较复杂的,要实现接口才能进行遍历,有没有简单些的方法呢?答案是肯定的。且看下面。yield关键字的用法:1.为当前类型添加一个任意方法,但是要求该方法的返回值类型必须是IEnumerable: 1 class Person 2 {...
分类:
其他好文 时间:
2014-07-23 11:39:06
阅读次数:
232