xiaxia

2007年9月29日 #

为泛型列表创建迭代器

摘要: 在本示例中,泛型类Stack实现泛型接口 IEnumerator。声明了一个类型 T 的数组,并使用 Push 方法给数组赋值。在 GetEnumerator 方法中,使用 yield return 语句返回数组的值。 还实现非泛型 GetEnumerator,因为 IEnumerable 继承自 IEnumerable。此示例显示了典型的实现,在该实现中,非泛型方法直接将调用转给泛型方法。 ... 阅读全文

posted @ 2007-09-29 09:40 Array 阅读(173) 评论(0) 推荐(0) 编辑

使用迭代器

摘要: 创建迭代器最常用的方法是对 IEnumerable 接口实现 GetEnumerator 方法,例如: public System.Collections.IEnumerator GetEnumerator() { for (int i = 0; i < max; i++) { yield return i; } } GetEnumerator 方法的存在... 阅读全文

posted @ 2007-09-29 09:33 Array 阅读(196) 评论(0) 推荐(0) 编辑

.NET代码编写规范

摘要: 下面是根据FxCop整理的.NET代码编写规范,仅供参考。一、 Design(设计)1. Abstract types should not have constructors 抽象类不应该声明构造方法2. Assemblies should have valid strong names 程序集应该具有强名称3. Avoid empty interfaces 避免使用空的接口4. Avoid e... 阅读全文

posted @ 2007-09-29 09:18 Array 阅读(229) 评论(0) 推荐(0) 编辑

yield迭代器

摘要: // 版权所有 (C) Microsoft Corporation。保留所有权利。 using System; using System.Collections.Generic; using System.Text; namespace Yield { class Yield { public static class NumberList { ... 阅读全文

posted @ 2007-09-29 09:02 Array 阅读(135) 评论(0) 推荐(0) 编辑

泛型實例-1

摘要: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebContr... 阅读全文

posted @ 2007-09-29 09:00 Array 阅读(201) 评论(0) 推荐(0) 编辑

导航