close
這次主要介紹串列類型之集合為:
1.List<T> : 最常用之集合串列,可透過索引來存取任意位置之元素。
2.LinkedList<T> : 此類別提供比List<T>效率更好的插入與刪除操作。
IList<T> 介面:
串列之基本功能都定義在ILlist<T>之中,故先了解一下其介面:
public interface IList<T> : ICollection , IEnumerable<T> , IEnumerable
{
T this [int index] {get; set;} //索引子
int IndexOf(T item) //尋找特定元素並回傳其位置
void Insert(int index , T item); //插入元素到指定位置
void RemoveAt(int index); //移除指定位址之元素
}
如上圖IList<T> 延伸至 ICollection<T>,並增加了串列之基本操作。(利用索引子取得或修改集合中元素,插入元素至指定位址...)
其中IndexOf 方法是以線性搜尋去找,如果沒有找到回傳-1。
另外在.NET Framework 中 implementation IList<T>之類別有:
1.Array
2.List<T>
3.Collection<T>
4.ObservableCollection<T>
Example : List<T>
全站熱搜