摘要: 用C#实现一个类的IEnumerable接口时有两种方法:1)实现非泛型IEnumerable接口;2)实现泛型IEnumerable(T)接口。如果采用方法1,当集合元素T是值类型时,将涉及到巨多的boxing和unboxing操作。因此,理所当然地采用方法2;例如,以下代码采用方法2实现枚举从指定偏移开始所有整数using System.Collections.Generic;class Ints : IEnumerable { private readonly int offset; public Ints(int o) { offset = o; } public I... 阅读全文
posted @ 2013-07-25 17:08 protorock 阅读(1560) 评论(0) 推荐(0) 编辑