140 likes | 277 Views
Collections. Presented By : Muhammad Atif Hussain Deputy Manager IT (Takaful Pakistan Limited) Technologies Consultant (AUC Technologies) MCS(KU) MSCS(SZABIST) MCP MCAD MCSD MCTS (Windows, Web, Distributed Applications) MCPD (Enterprise Applications) MCT(Microsoft Certified Trainer).
E N D
Collections Presented By : Muhammad Atif HussainDeputy Manager IT (Takaful Pakistan Limited)Technologies Consultant (AUC Technologies)MCS(KU)MSCS(SZABIST)MCPMCADMCSDMCTS (Windows, Web, Distributed Applications)MCPD (Enterprise Applications)MCT(Microsoft Certified Trainer)
Data Structure Types of Data structure Examples Agenda
Array ArrayList List<> LinkedList<> Dictionary HashTable HashSet Stack Queue Type of Data Structure (System.Collections)
Array • Most common and simplest • List of Objects • All the Objects are of same types • Specified number of Objects [object type][] myArray = new [object type][number of elements] Examples int[] myIntArray = new int[5]; int[] myIntArray2 = { 0, 1, 2, 3, 4 };
ArrayList • Dynamic Array • Any type of Objects • Any amount of Objects • Expanded as more item are added • Casting required when value retrieved Examples: ArrayListmyArrayList = new ArrayList(); myArrayList.Add(56); myArrayList.Add("String"); intarrayListValue = (int)myArrayList[0];
Typed ArrayList Dynamic Array Same type of Objects Examples: List<int> intList = new List<int>(); intList.Add(45); intList.Add(34); int listValue = intList[0]; Hint: For primative data types (int, bool, etc.) using a List is much faster than ArrayList List<>
Series of Objects linked together in Nodes Object Value Next Node Previous Node Adding values in the middle of the list is extremely fast Memory cost down to minimum Retrieving a value is not a straight forward Examples: LinkedList<int> list = newLinkedList<int>(); list.AddLast(6); LinkedList<>
Programmer can handle index at their own Keys is also an Object Retrieving a value is pretty straight forward Examples: Dictionary<string, int> myDictionary = new Dictionary<string, int>(); myDictionary.Add("one", 1); myDictionary.Add("twenty", 20); int myInt = myDictionary["one"]; Dictionary<>
Similar to Dictionary Data Structure Also takes in Key/Value pair but generic Objects opposed to typed data Values are stored in order of HashCode (Key) but Dictionary does keep items in the same order HashTable stores items faster than a Dictionary Examples: Hashtable myTable = new Hashtable(); myTable.Add("name", "Vb.NET"); myTable.Add(1, "C#.NET"); HashTable
Introduced in .NET Framework 3.5 Resemble to List<> Data structure Its does not allow duplicate value Examples: HashSet<int> mySet = new HashSet<int>(); mySet.Add(3); mySet.Add(3); mySet.Add(5); List<int> myListFromSet = mySet.ToList<int>(); int myInt = myListFromSet[1]; HashSet
Resemble to ArrayList Push (Add) , Pop (Get), LIFO Stack works with Objects, Stack<> works with specified Object Examples: Stack stack = new Stack(); Stack<string> stack = new Stack<string>(); Stack<string> stack = new Stack<string>(); stack.Push("1"); stack.Push("2"); stack.Push("3");while (stack.Count > 0){MessageBox.Show(stack.Pop());} Stack and Stack<>
Very similar to Stack Enqueue (Add), Dequeue (Remove) Queues goes by FIFO Examples: Queue<string> queue = new Queue<string>(); queue.Enqueue("1"); queue.Enqueue("2"); queue.Enqueue("3"); while (queue.Count > 0){MessageBox.Show(queue.Dequeue());} Queue
? Questions