惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
月光博客
月光博客
IT之家
IT之家
B
Blog RSS Feed
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
U
Unit 42
博客园_首页
B
Blog
V
V2EX
腾讯CDC
Vercel News
Vercel News
量子位
Microsoft Security Blog
Microsoft Security Blog

博客园 - 糊涂小猪

ASP.NET页面请求流程 工作气氛 程序员的人生 利用reflector工具导出工程文件 按评论数排序会出现两个一模一样的文章,是BUG么? ORACLE中按长度分割字符串(保持单词完整性和数值完整性) CLS理解 starteam 中文手册 不会技术的比会技术的好混,啥世道现在!! 自定义COMBOBOX控件 ORACLE中批处理的执行 日志文件的生成 C#取得当前窗体图片 MENUITEMS中一个被忽略的属性 C#继承机制 Start without Debugging VS start C#中对ini文件的操作。 C#中提取字符串的解决方法 C#中的[DllImport("kernel32.dll")]的意思是啥?困惑ing。
继承CollectionBase来扩展自定义的集合类型
糊涂小猪 · 2007-03-21 · via 博客园 - 糊涂小猪

 Introduction
     很多时候我们在开发的过程中都要用到自定义集合类型.,CollectionBases此基类旨在使实施者创建强类型自定义集合变得更容易。实施者应扩展此基类,而不应创建自己的基类。所以我们在自定义集合类型的时候,不应该再创建自己的基类而应该扩展此基类.
 
Content
   下面代码就是通过继承CollectionBase来扩展自定义的Collection.

 using  System;
 nameSpace MyCollections
 {
      public class MyCollection: System.Collections.CollectionBase
     
     // Construct fuction
     public MyCollection()
      {
      // add code here
     }
   
 //Set the Index of this collection
 public object  this[int Index]
  {
     set
      {
          List[Index]   = value;
      }
     get
     {
         return  (oject)List[Index];
     }
 //Add Object into Collection
 public int Add(Object sender)
{
      return List.Add(sender);
}
// Remove Object
 pubic void Remove(Object sender)
{
   List.Remove(sender);
}
// Insert Object into assign positionn
public void Insert(int index,object sender)
{
   List.Insert(index,sender);
}
//IndexOf  assign object
public int IndexOf(object sender)
{
   reutrn List.IndexOf(sender);
}
//Judge object whether Collections is contain.
public bool Contains(object sender)
{
return List.Containers(sender);
}
 }
}
 因为CollectionBase类中包含了List的受属性,所以可以通过IList提供的接口来实现上述的功能.
有错误的地方请多加指点..3 Q...