C#中ArrayList INSERT的问题...求助中

来源:百度知道 编辑:UC知道 时间:2024/06/08 05:49:46
资料上说因为index参数的存在,arraylist的insert方法比 add方法多一个可能产生异常,为什么啊?

请讲详细点,好懂些,谢谢^.^

Insert方法比Add多的异常是由参数index引起的。当index小于0或大于Count的时候,系统会认为无法插入该项目,引发异常。

以下是两个方法的具体信息。

Insert方法:
参数
index
类型:System..::.Int32

从零开始的索引,应在该位置插入 value。

value
类型:System..::.Object

要插入的 Object。该值可以为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing)。

实现
IList..::.Insert(Int32, Object)

异常
异常 条件
ArgumentOutOfRangeException index 小于零。

- 或 -

index 大于 Count。

NotSupportedException ArrayList 为只读。

- 或 -

ArrayList 具有固定大小。

Add方法:
参数
value
类型:System..::.Object

要添加到 ArrayList 的末尾处的 Object。该值可以为 nullNothingnullptrnull 引用(在 Visual Basic 中为 Nothing)。

返回值
类型:System..::.Int32

ArrayList 索引,已在此处添加了 value。

实现
IList..::.Add(Object)

异常
异常 条件
NotSupportedException ArrayList 为只读。

- 或 -

ArrayList 具有固定大小。

insert 是 使劲往