Victor.Stone
dot net 备忘录
posts - 21,  comments - 25,  trackbacks - 0

关于 CollectionBase ArrayList 的比较

 

 

CollectionBase

ArrayList

相同

命名空间相同System.Collections,

都支持IList, ICollection, Ienumerable三个接口

 

不同

抽象类

--

public abstract class CollectionBase : IList, ICollection, Ienumerable

为强类型集合提供 abstract 基类。

public class ArrayList : IList, ICollection, IEnumerable, ICloneablee

使用大小可按需动态增加的数组实现 System.Collections.IList 接口。

操作对象为派生后的强类型类

主要操作对象为 Object

主要靠list

(public interface IList : ICollection, IEnumerable)接口属性来实现对象的增删改:如List.Add,

本身已经实现,但为虚方法

 

如果从CollectionBase进行派生, 实现索引非常省事:

    public class Cards : CollectionBase
    
{
        
public void Add(Card newCard)
        
{
            List.Add(newCard);
        }


        
public void Remove(Card oldCard)
        
{
            List.Remove(oldCard);
        }


        
public Cards()
        
{
        }


        
//实现索引符
        public Card this[int cardIndex]
        
{
            
get
            
{
                
return (Card)List[cardIndex];
            }

            
set
            
{
                List[cardIndex] 
= value;
            }

        }

    }

posted on 2008-02-26 12:18 Victor.Stone 阅读(1267) 评论(0)  编辑 收藏 引用 所属分类: .net framework
只有注册用户登录后才能发表评论。

<2008年2月>
272829303112
3456789
10111213141516
17181920212223
2425262728291
2345678

常用链接

留言簿(2)

随笔分类(17)

文章分类

搜索

  •  

积分与排名

  • 积分 - 23851
  • 排名 - 192

最新随笔

阅读排行榜