Collection and Generics
-
Upload
melick-baranasooriya -
Category
Technology
-
view
1.560 -
download
0
description
Transcript of Collection and Generics
C# Collections & Generics <>Melick Rajee Baranasooriyahttp://melick-rajee.blogspot.com/
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
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
Collections ..• BitArray• Use to store arrays of bits• True = 1 , False = 0;
• Stack• LIFO• Methods
• Pop• Push• Peek
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
Collections ..• Hashtable• presents a collection of key/value pairs• Access using key
Generic ?• Generic classes and methods combine reusability
• Type Safe
• Efficiency
• Extend the behavior or Collection
• Available in • System.Collections.Generic
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
Thank You.