Collection and Generics

9
C# Collections & Generics <> Melick Rajee Baranasooriya http://melick-rajee.blogspot.com/

description

Second Session about Collection and Generics @ IOM

Transcript of Collection and Generics

Page 1: Collection and Generics

C# Collections & Generics <>Melick Rajee Baranasooriyahttp://melick-rajee.blogspot.com/

Page 2: Collection and Generics

Collections ?• Classes for data storage and retrieval• Data can be storage using• Stacks• Queues• Lists• Hash tables• ..

• Available under• System.Collections or System.Collections.Generic• ICollection, IComparer, IEnumerable, IList, IDictionary, and

IDictionaryEnumerator

Page 3: Collection and Generics

Collections• ArrayList • Not guaranteed to be sorted• Capacity of a ArrayList = Number of elements• Capacity will be increase when adding• Zero Base Index

• Good for value types• Can use to pass parameters as well

Page 4: Collection and Generics

Collections ..• BitArray• Use to store arrays of bits• True = 1 , False = 0;

• Stack• LIFO• Methods

• Pop• Push• Peek

Page 5: Collection and Generics

Collections ..• SortedList• Element can be accessed by its key, • internally maintains two arrays to store the elements of the list • Sorting based on the key• Adding operation is slow but retrieval is faster

• Queue• FIFO• Manage Sequence

• Enqueue• Dequeue• Peek

Page 6: Collection and Generics

Collections ..• Hashtable• presents a collection of key/value pairs• Access using key

Page 7: Collection and Generics

Generic ?• Generic classes and methods combine reusability

• Type Safe

• Efficiency

• Extend the behavior or Collection

• Available in • System.Collections.Generic

Page 8: Collection and Generics

Generic Data Structures• Stack<T>• List<T>• Queue<T>• KeyValuePair<TKey, TValue>• Dictionary<TKey, TValue>

• Using Generic Methods and Expressions (lambda expressions)• Simple Types• Complex Types

Page 9: Collection and Generics

Thank You.