Presentation is loading. Please wait.

Presentation is loading. Please wait.

Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke.

Similar presentations


Presentation on theme: "Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke."— Presentation transcript:

1 Session 07 Module 13 - Collections

2 Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke the mothod that is referred to by the delegate, an instance of the delegate is created.  A Event is a data member that enables an object to provide notifications to other objects about a particular action.  For using an event, you must first declare a delegate and an event, define an event handler to handle the event and finally associate the handler to the event.

3 Collections / Session 7 / 3 of 32 Module 13 – Objectives (1)  List and explain the commonly used classes and interfaces in the System.Collections namespace  List and explain the commonly used classes and interface in the System.Collection.Generic namespace  Describle the commonly used methods and properties of ArrayList class

4 Collections / Session 7 / 4 of 32 Module 13 – Objectives (2)  Describe the commonly used methods and properties of Hashtable class  Describe the commonly used methods and properties of SortedList class  Describe the commonly used methods and properties of Dictionary class

5 Collections / Session 7 / 5 of 32 What is Collection?  A collection is a set of related data that may not necessary belong to the same data type.  Element in collection can be set or modified at run time

6 Collections / Session 7 / 6 of 32 System.Collections namespace  System.Collections namespace in C# allow to construct and manipulate a collection of objects.  This collection can include elements of difference data types.

7 Collections / Session 7 / 7 of 32 Classes

8 Collections / Session 7 / 8 of 32 Interface

9 Collections / Session 7 / 9 of 32 System.Collections.Generic namespace  Generic allow you to define data structures that consist of functionalities which can be implemented for any data type.  Generic allow you to reuse a code for different data types.  System.Collections.Generic namespace is similar to the System.Collections namespace as both allow you to create collections. However, generic collection are type safe

10 Collections / Session 7 / 10 of 32 System.Collections.Generic class

11 Collections / Session 7 / 11 of 32 System.Collections.Generic Interface

12 Collections / Session 7 / 12 of 32 ArrayList class  ArrayList class is a variable-length array that can dynamically increase or decrease in size.  Unlike Array class, this class can store elements of different data type.  The default capacity of an ArrayList is 16, if the number of elements in list reached the specified capacity, the capacity of list is doubled automatically.  It can accept null value and can also include duplicate elements

13 Collections / Session 7 / 13 of 32 Methods

14 Collections / Session 7 / 14 of 32 Properties

15 Collections / Session 7 / 15 of 32 Hash table class  Hashtable class allow you to create collections in the form of keys and values.  It generates a hash table which associated keys with their corresponding values.

16 Collections / Session 7 / 16 of 32 Methods

17 Collections / Session 7 / 17 of 32 Property

18 Collections / Session 7 / 18 of 32 SortedList class  SortedList class presents a collections of pair value and Key  By default SortedList sorts the elements in ascending order.  These elements either accessed using the corresponding keys or index number

19 Collections / Session 7 / 19 of 32 Hashtable vs. SortedList  SortedList class is a combination of the Hashtable class and the ArrayList class.  The difference between the Hashtable class and the SortedList class is that the values in object of SortedList class are sorted by their keys as well as by their index position.  However, the execution of the program using the SortedList class is slower than the programming using the Hashtable class due to sorting process.

20 Collections / Session 7 / 20 of 32 Hashtable vs. SortedList

21 Collections / Session 7 / 21 of 32 Methods

22 Collections / Session 7 / 22 of 32 Property

23 Collections / Session 7 / 23 of 32 Dictionary generic class  It consists of a generic collection of elements organized in key and value pairs.  It maps the keys to their corresponding values.  Unlike other collections in the System.Collections namespace, it is used to create a collection of a single data type at a time  The Dictionary class does not allow null value as elements.

24 Collections / Session 7 / 24 of 32 Methods

25 Collections / Session 7 / 25 of 32 Properties

26 Collections / Session 7 / 26 of 32 Dictionary Generic class  System.Collection.Generic namespace contains commonly used class is Dictionary generic class.  Dictionary generic class consists of a generic collection of elements organized in key and value pair.

27 Collections / Session 7 / 27 of 32 Dictionary generic class  Unlike other collection in the System.Collections namespace, it is used to create a collection of a single data type at a time.  Dictionary does not allow null value as elements.  Dictionary

28 Collections / Session 7 / 28 of 32 Method

29 Collections / Session 7 / 29 of 32 Property

30 Collections / Session 7 / 30 of 32 Session 13 – Summary (1)  Collection allow you to manage a group of objects dynamically at run-time.  The System.Collections namespace contains different collections such as arrays, hash table, list and dictionary.  System.Collection.Generic consists of generic collections that allow resuability of code and provide better type safety.

31 Collections / Session 7 / 31 of 32 Session 13 – Summary (2)  ArrayList class allow to increase and decrease the size of the collection during program execution.  It allow you to store elements of different data types.  Hashtable class stores elements as key and value pair where the data is organized based on the hash code.  Each value in the hash table is uniquely identified by its key

32 Collections / Session 7 / 32 of 32 Session 13 – Summary (3)  SortedList class allow you to store elements as key and value pairs where the data is sorted based on the key.  It allow you to access elements from the collection using the key or the index number.  Dictionary generic class represents a collection of elements organized in key and value pairs.  The key value is used to retrieve value from the collection


Download ppt "Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke."

Similar presentations


Ads by Google