| 发表于:2007-01-31 15:20:45 楼主 |
在c#一个类从几个接口派生,可以不全实现这些接口的方法吗?代码如下: 相关接口 ================================================================== // 摘要: // 表示可按照索引单独访问的对象的非泛型集合。 [comvisible(true)] public interface ilist : icollection, ienumerable { // 摘要: // 获取一个值,该值指示 system.collections.ilist 是否具有固定大小。 // // 返回结果: // 如果 system.collections.ilist 具有固定大小,则为 true;否则为 false。 bool isfixedsize { get; } // // 摘要: // 获取一个值,该值指示 system.collections.ilist 是否为只读。 // // 返回结果: // 如果 system.collections.ilist 为只读,则为 true;否则为 false。 bool isreadonly { get; } // 摘要: // 获取或设置指定索引处的元素。 // // 参数: // index: // 要获得或设置的元素从零开始的索引。 // // 返回结果: // 指定索引处的元素。 object this[int index] { get; set; } // 摘要: // 将某项添加到 system.collections.ilist 中。 // // 参数: // value: // 要添加到 system.collections.ilist 的 system.object。 // // 返回结果: // 新元素的插入位置。 int add(object value); // // 摘要: // 从 system.collections.ilist 中移除所有项。 void clear(); // // 摘要: // 确定 system.collections.ilist 是否包含特定值。 // // 参数: // value: // 要在 system.collections.ilist 中查找的 system.object。 // // 返回结果: // 如果在 system.collections.ilist 中找到 system.object,则为 true;否则为 false。 bool contains(object value); // // 摘要: // 确定 system.collections.ilist 中特定项的索引。 // // 参数: // value: // 要在 system.collections.ilist 中查找的 system.object。 // // 返回结果: // 如果在列表中找到,则为 value 的索引;否则为 -1。 int indexof(object value); // // 摘要: // 将一个项插入指定索引处的 system.collections.ilist。 // // 参数: // value: // 要插入 system.collections.ilist 中的 system.object。 // // index: // 从零开始的索引,应在该位置插入 value。 void insert(int index, object value); // // 摘要: // 从 system.collections.ilist 中移除特定对象的第一个匹配项。 // // 参数: // value: // 要从 system.collections.ilist 移除的 system.object。 void remove(object value); // // 摘要: // 移除指定索引处的 system.collections.ilist 项。 // // 参数: // index: // 从零开始的索引(属于要移除的项)。 void removeat(int index); } // 摘要: // 定义所有非泛型集合的大小、枚举数和同步方法。 [comvisible(true)] public interface icollection : ienumerable { // 摘要: // 获取 system.collections.icollection 中包含的元素数。 // // 返回结果: // system.collections.icollection 中包含的元素数。 int count { get; } // // 摘要: // 获取一个值,该值指示是否同步对 system.collections.icollection 的访问(线程安全)。 // // 返回结果: // 如果对 system.collections.icollection 的访问是同步的(线程安全),则为 true;否则为 false。 bool issynchronized { get; } // // 摘要: // 获取可用于同步 system.collections.icollection 访问的对象。 // // 返回结果: // 可用于同步对 system.collections.icollection 的访问的对象。 object syncroot { get; } // 摘要: // 从特定的 system.array 索引处开始,将 system.collections.icollection 的元素复制到一个 system.array // 中。 // // 参数: // array: // 作为从 system.collections.icollection 复制的元素的目标位置的一维 system.array。system.array // 必须具有从零开始的索引。 // // index: // array 中从零开始的索引,从此处开始复制。 void copyto(array array, int index); } // 摘要: // 公开枚举数,该枚举数支持在非泛型集合上进行简单迭代。 [comvisible(true)] [guid( "496b0abe-cdee-11d3-88e8-00902754c43a ")] public interface ienumerable { // 摘要: // 返回一个循环访问集合的枚举数。 // // 返回结果: // 可用于循环访问集合的 system.collections.ienumerator 对象。 [dispid(-4)] ienumerator getenumerator(); } =================================================================== [serializable] [comvisible(true)] public abstract class collectionbase : ilist, icollection, enumerable { protected collectionbase(); protected collectionbase(int capacity); public int capacity { get; set; } public int count { get; } protected arraylist innerlist { get; } protected ilist list { get; } protected virtual void onclear(); protected virtual void onclearcomplete(); protected virtual void oninsert(int index, object value); protected virtual void onremove(int index, object value); protected virtual void onset(int index, object oldvalue, object newvalue); protected virtual void onsetcomplete(int index, object oldvalue, object newvalue); protected virtual void onvalidate(object value); public void removeat(int index); // public class profilepropertybindingcollection : collectionbase { internal event eventhandler collectionchanged; internal profilepropertybindingcollection() { } public profilepropertybinding this[int index] { get { return (profilepropertybinding)innerlist[index]; } set { innerlist[index] = value; } } public void add(profilepropertybinding binding) { innerlist.add(binding); } public void insert(int index, profilepropertybinding binding) { innerlist.insert(index, binding); } protected virtual void oncollectionchanged(eventargs e) { if (collectionchanged != null) { collectionchanged(this, e); } } public void remove(profilepropertybinding binding) { innerlist.remove(binding); } protected override void oninsertcomplete(int index, object value) { base.oninsertcomplete(index, value); oncollectionchanged(eventargs.empty); } protected override void onsetcomplete(int index, object oldvalue, object newvalue) { base.onsetcomplete(index, oldvalue, newvalue); oncollectionchanged(eventargs.empty); } protected override void onremovecomplete(int index, object value) { base.onremovecomplete(index, value); oncollectionchanged(eventargs.empty); } protected override void onclearcomplete() { base.onclearcomplete(); oncollectionchanged(eventargs.empty); } } } //在以上的类实现过程中,有好几个接口的方法都没有实现,如ilist下的 bool contains。我记得好像类必须实现接口的所有方法吧? |
|
|
|
|