您的位置:首页 > 其它

WPF中List的Add()与Insert()方法的区别

2016-03-15 15:37 423 查看
先来看看定义:

//
// Summary:
// Inserts an element into the System.Collections.Generic.List<T> at the specified
// index.
//
// Parameters:
// index:
// The zero-based index at which item should be inserted.
//
// item:
// The object to insert. The value can be null for reference types.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// index is less than 0.-or-index is greater than System.Collections.Generic.List<T>.Count.


View Code
public void Insert(int index, T item); 该方法接受两个参数,第一个为下标,第二个为要添加的元素

需求: 要求往List中添加数据,而且后面加的数据始终要排在第一的位置,

添加 5 6 7 8 9,通过Insert(0, number), 这里的0就代表第一个位置,那么结果为{9, 8, 7, 6, 5}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: