110 likes | 248 Views
Fun with Lists for the Novice and Expert. Scott Reed Brain Hz Software scott@brainhzsoftware.com (760) 845-3320. In the beginning…. There were arrays… And there were System.Collections ArrayList : IList : ICollection : IEnumerable Hashtable : IDictionary : ICollection …
E N D
Fun with Listsfor the Novice and Expert Scott Reed Brain Hz Software scott@brainhzsoftware.com (760) 845-3320
In the beginning… • There were arrays… • And there were System.Collections • ArrayList : IList : ICollection : IEnumerable • Hashtable : IDictionary : ICollection … • Various others • Queue, Stack, SortedList
IEnumerable and IEnumerator • Pull style iteration (better than Java :) • IEnumerable • IEnumeratorGetEnumerator() • IEnumerator • boolMoveNext(); • object Current { get; } • What foreach uses • foreach (object item in arrayList)
ICollection • Count • CopyTo • SyncRoot and IsSynchronized*
IList • Adding and removal • Add, Insert, Remove, RemoveAt • Clearing (via Clear) • Random access • has an indexer • Finding • Contains, IndexOf • Properties • IsFixedSize, IsReadOnly
IDictionary • Adding and removal • Add, Remove and Clear only • Random access • has an indexer • Finding • Contains only • Properties • IsFixedSize, IsReadOnly • Collections • Keys and Values
Side note: What about Arrays? • int[] : Array : IList : ICollection : IEnumerable • Fixed size collections • Add and Remove not supported
What is the problem? • Dangerous - Type safety • Ugly - Casting • Performance of value types (boxing and unboxing)
Extras • FindAll • Sort • FxCopwarnings • BindingLists • ObservableCollections • DataTable • yield
Thank You Scott Reed Brain Hz Software scott@brainhzsoftware.com (760) 845-3320