ArrayList.RemoveAt() 方法思考

-bootblack- 2016-03-27 11:00:21
 int[] arr = new int[] { 1, 2, 3, 4, 5, 6 };
ArrayList List = new ArrayList(arr);
List.Remove(1);
foreach (int i in List)
Console.Write(i + " ");





请教大神:这个方法的形参index是"从零开始的索引",可是当我使用参数1,按照我的理解应该是删除2啊,为什么删除的是1?
而当我在形参中写入0,实际上什么也没删除,恳请大神指教
...全文
668 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
江南小鱼 2016-03-28
  • 打赏
  • 举报
回复
引用 4 楼 liuchangkk1 的回复:
哦,是的,是小弟大意了,感谢大神 再次请问大神:如果想查找某个API该如何使用,如何使用MSDN啊? 这个List.RemoveAt() MSDN :Removes the first occurrence of a specific object from the List<T>从哪里可以查到,有中文版的吗?
一般度娘,可以度娘到MSDN的链接
-bootblack- 2016-03-27
  • 打赏
  • 举报
回复
哦,是的,是小弟大意了,感谢大神 再次请问大神:如果想查找某个API该如何使用,如何使用MSDN啊? 这个List.RemoveAt() MSDN :Removes the first occurrence of a specific object from the List<T>从哪里可以查到,有中文版的吗?
nry19871012 2016-03-27
  • 打赏
  • 举报
回复
函数调用错了。

 int[] arr = new int[] { 1, 2, 3, 4, 5, 6 };
            ArrayList List = new ArrayList(arr);
            List.Remove(1);//此处,按你的想法应该调用RemoveAt()。Remove是删除列表中对应的项,RemoveAt删除对应索引的项。
            foreach (int i in List)
                Console.Write(i + " ");
鏡椛氹鈅 2016-03-27
  • 打赏
  • 举报
回复
看你自己的代码 你用的是List.Remove(1); 你查询的是List.RemoveAt(); List.Remove() MSDN :Removes the first occurrence of a specific object from the List<T>.(从列表中移除第一个指定对象) List.RemoveAt() MSDN:Removes the element at the specified index of the List<T>.(移除列表中指定索引处的元素)
乐百川 2016-03-27
  • 打赏
  • 举报
回复
请注意Remove和RemoveAt的区别……

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧