首页 > 其他 > 详细

CollectionBase

时间:2015-11-17 12:24:04      阅读:264      评论:0      收藏:0      [点我收藏+]

自定义Collection类最快的一种方式:继承CollectionBase抽象类


CollectionBase类提供了一套可以实现构造自身群集的抽象方法集合。
CollectionBase 类还提供了一种基础的数据结构——InnerList(一个 ArrayList) 。此结构可以用作自身类的基础。

 

using System.Collections命名空间之下:

 

 

namespace MyCollectionBase
{
    using System.Collections;

class Program { static void Main(string[] args) { myCollection c = new myCollection(); c.Add("DSC"); c.Add("CSC"); c.Add("BSC"); c.Add("ASC"); foreach (string item in c) { Console.WriteLine(item); } Console.WriteLine(c.Length()); Console.ReadKey(); } } class myCollection : CollectionBase { public void Add(object item) { InnerList.Add(item); } public int Length() { return InnerList.Count; } public void Delete(object item) { InnerList.Remove(item); } public void Clear() { InnerList.Clear(); } } }

 

CollectionBase

原文:http://www.cnblogs.com/Francis-YZR/p/4971068.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!