1 / 14

Collections

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).

feleti
Download Presentation

Collections

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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)

  2. Data Structure Types of Data structure Examples Agenda

  3. Array ArrayList List<> LinkedList<> Dictionary HashTable HashSet Stack Queue Type of Data Structure (System.Collections)

  4. 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 };

  5. 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];

  6. 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<>

  7. 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<>

  8. 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<>

  9. 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

  10. 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

  11. 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<>

  12. 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

  13. ? Questions

More Related