SlideShare a Scribd company logo
Implementing
Collections and
Generics
Overview
 Examining Collections and Collection Interfaces
 Working with Primary Collection Types
 Working with Generic Collections
 Working with Specialized Collections
 Working with Collection Base Classes
Lesson 1: Examining Collections and
Collection Interfaces
 What Are Collections?
 What Are Generic Collections?
 What Are Collection Interfaces?
 Discussion: Identifying the Uses of Advanced and
Generic Collections and Collection Interfaces
Collections store arbitrary objects in a structured manner.
Types of collections available within the .NET Framework
are:
What Are Collections?
Arrays
Advanced collections
 Non-generic collections
 Generic collections
What Are Generic Collections?
Generic collections support the storage of both value types
and reference types. Only a single data type is allowed to
be stored inside a generic collection. Following are the
generic collection types:
Generic Dictionary
Generic List
Generic Stack
Generic Queue
Generic LinkedList
Generic Interface
What Are Collection Interfaces?
A collection interface allows a collection to support a
different behavior. Collection interfaces are:
IComparable
ICollection
IList
IComparer
IEqualityComparer
IDictionary
IEnumerable
IEnumerator
Lesson 2: Working with Primary
Collection Types
 How a Flexible Collection of Reference Types Is
Created by Using ArrayList
 How Circular Collections Are Managed by Using Stack
and Queue Classes
 How to Iterate Through the Elements of a Collection by
Using Enumerators
 How Reference Types Are Accessed Based on
Key/Value Pairs and Comparers
 How Boolean Values Are Stored in a BitArray by
Using the BitArray Class
 Discussion: Identifying the Uses of Non-Generic
Collections
How a Flexible Collection of Reference
Types Is Created by Using ArrayList
A class representing a list, which is similar to a
single-dimensional array that you can
resize dynamically
ArrayList
Dim countries As New ArrayList()
countries.Add("Belgium")
countries.Add("China")
countries.Add("France")
countries.Add("New Zealand")
ArrayList countries = new ArrayList();
countries.Add("Belgium");
countries.Add ("China");
countries.Add("France");
countries.Add("New Zealand");
Visual Basic
C#
How Circular Collections Are Managed
by Using Stack and Queue Classes
A stack can be visualized as a stack of books arranged
one on top of the other. You can pick or access the top-
most book in the stack because it was the last book
added. The Stack class works on the same principle
Stack
A queue can be visualized as a line in a grocery store,
where customers enter the queue from the rear and exit
the queue from the front. Therefore, the first customer to
enter the queue is the first to exit it. The Queue class
follows the same principle
Queue
How to Iterate Through the Elements of
a Collection by Using Enumerators
To support enumeration, you:
 Implement the IEnumerable interface in Visual Basic
 Use the yield statement in C# rather than implementing
the IEnumerable interface
How Reference Types Are Accessed Based on
Key/Value Pairs and Comparers
Comparer class compares two objects to detect
if they are less than, greater than, or equal to
one another
Hashtable class represents a collection of
name/value pairs, organized based on the hash
code of the key being specified
SortedList class represents a collection of
name/value pairs, accessible either by key or by
index, but sorted only by keys
How Boolean Values Are Stored in a
BitArray by Using the BitArray Class
BitArray is a class in the .NET Framework that
allows you to implement bit structures
BitArray
Class
Lesson 3: Working with Generic
Collections
 How Type-Safe Collections Are Created by Using
Generic List Types
 How Type-Safe Collections Are Created by Using
Generic Collections
 How Reference Types Are Accessed Based on
Type-Safe Key/Value Pairs
 How Type-Safe Doubly Linked Lists Are Created by
Using Generic Collections
 Discussion: Identifying the Uses of Generic Collections
How Type-Safe Collections Are Created
by Using Generic List Types
Generic List class:
Provides methods to search, sort, and manipulate
the elements of a generic list
Creates a generic list that provides the behavior of
an ArrayList
How Type-Safe Collections Are Created
by Using Generic Collections
The generic Stack class represents a variable size LIFO
collection of objects of same data typeGeneric
Stack
Class
The generic Queue class represents a variable size
FIFO collection of elements of same data type
Generic
Queue Class
How Reference Types Are Accessed Based
on Type-Safe Key/Value Pairs
The .NET Framework provides the following classes in the
System.Collections.Generic namespace that help you to
add name and value pairs to a collection:
Dictionary
SortedList
SortedDictionary
How Type-Safe Doubly Linked Lists Are
Created by Using Generic Collections
Generic LinkedList class:
Defines nodes that have a common data type, and
each node points to the previous and following nodes
Helps create and manage a strongly typed doubly
linked list
Lesson 4: Working with Specialized
Collections
 What are Specialized Collections?
 How Type-Safe Strings Are Created by Using
Specialized String Classes
 How High-Performance Dictionaries Are Created by
Using Specialized Collections
 How Collections with String-Based Keys Are
Created by Using Specialized Classes
 How Data Is Stored Efficiently in Memory by Using
Specialized Bit Structures
 Practice: Evaluate When to Use a Specific
Generic Collection
What Are Specialized Collections?
Specialized collections are predefined collections that
serve a special or highly specific purpose.
Specialized collection types are:
String classes
Dictionary classes
NamedCollection classes
Bit structures
How Type-Safe Strings Are Created by
Using Specialized String Classes
Types of specialized string collections are:
StringCollection
StringDictionary
StringEnumerator
CollectionsUtil
How High-Performance Dictionaries Are
Created by Using Specialized Collections
Types of specialized dictionary collections are:
Is a simple implementation of the IDictionary
interface by using a singly linked list
ListDictionary
Uses the appropriate implementation for a
dictionary depending on the size of
the collection
HybridDictionary
Represents a collection of key/value pairs
that are ordered based on the key or
the index
OrderedDictionary
How Collections with String-Based Keys
Are Created by Using Specialized Classes
Classes in the System.Collections.Specialized namespace
allow you to create collections with string-based keys.
These classes are:
NameObjectCollectionBase
NameObjectCollectionBase.KeysCollection
NameValueCollection
How Data Is Stored Efficiently in Memory
by Using Specialized Bit Structures
Bit structure stores Boolean values in binary series of 1s
and 0s and always uses 32 bits of storage
Two specialized bit structures are:
 BitVector32
 BitVector32.Section
Console.WriteLine(bv.ToString & " = " & bv.Data)
Dim b1 As Integer = BitVector32.CreateMask()
Dim b2 As Integer = BitVector32.CreateMask(b1)
bv(b1) = True
bv(b2) = True
Console.WriteLine(bv.ToString & " = " & bv.Data)
Dim s1 As BitVector32.Section = BitVector32.CreateSection(6)
Dim s2 As BitVector32.Section = BitVector32.CreateSection(3,
s1)
Visual Basic Code Example
Lesson 5: Working with Collection Base
Classes
How Custom Collections Are Created by Using Collection
Base Classes
How Custom Dictionary Types Are Created by Using
Dictionary Base Types
Discussion: Identifying the Differences Between Custom
Collections and Custom Dictionary Types
How Custom Collections Are Created
by Using Collection Base Classes
Two dictionary base classes are:
Represents an abstract class for a
strongly typed collection
CollectionBase Class
Represents an abstract base class for a
strongly typed non-generic collection
ReadOnlyCollectionB
ase Class
Defines a dictionary key/value pair in a
dictionary collection
How Custom Dictionary Types Are Created
by Using Dictionary Base Types
Two collection base classes are:
Provides the abstract base class for a
strongly typed collection of key value/pairs
DictionaryBase Class
DictionaryEntry
Structure
Review
This module described:
Examining collections and
collection interfaces
Working with primary collection types
Working with generic collections
Working with specialized collections
Working with collection base classes
Review
 Overview of Arrays
 Creating Arrays
 Using Arrays

More Related Content

Similar to Module 8 : Implementing collections and generics (20)

PPTX
C# Generic collections
Prem Kumar Badri
 
PPT
Generics Collections
phanleson
 
PPTX
Generics In and Out
Jaliya Udagedara
 
PPS
Net framework session02
Niit Care
 
PPTX
COLLECTIONS.pptx
SruthyPJ
 
ODP
(4) collections algorithms
Nico Ludwig
 
PPTX
C# Non generics collection
Prem Kumar Badri
 
PPTX
CSharp for Unity - Day 1
Duong Thanh
 
PDF
(4) collections algorithms
Nico Ludwig
 
PPTX
collections
Yaswanth Babu Gummadivelli
 
PPTX
Collection
Gayathri Ganesh
 
PPTX
Collections in .net technology (2160711)
Janki Shah
 
PPTX
2. overview of c#
Rohit Rao
 
PPTX
9collection in c#
Sireesh K
 
PDF
LectureNotes-03-DSA
Haitham El-Ghareeb
 
PPTX
Generic Programming & Collection
Arya
 
PPTX
Generic Programming & Collection
Arya
 
PDF
C# quick ref (bruce 2016)
Bruce Hantover
 
PPTX
Collections and generics
Miguel Angel Teheran Garcia
 
C# Generic collections
Prem Kumar Badri
 
Generics Collections
phanleson
 
Generics In and Out
Jaliya Udagedara
 
Net framework session02
Niit Care
 
COLLECTIONS.pptx
SruthyPJ
 
(4) collections algorithms
Nico Ludwig
 
C# Non generics collection
Prem Kumar Badri
 
CSharp for Unity - Day 1
Duong Thanh
 
(4) collections algorithms
Nico Ludwig
 
Collection
Gayathri Ganesh
 
Collections in .net technology (2160711)
Janki Shah
 
2. overview of c#
Rohit Rao
 
9collection in c#
Sireesh K
 
LectureNotes-03-DSA
Haitham El-Ghareeb
 
Generic Programming & Collection
Arya
 
Generic Programming & Collection
Arya
 
C# quick ref (bruce 2016)
Bruce Hantover
 
Collections and generics
Miguel Angel Teheran Garcia
 

More from Prem Kumar Badri (20)

PPTX
Module 15 attributes
Prem Kumar Badri
 
PPTX
Module 14 properties and indexers
Prem Kumar Badri
 
PPTX
Module 12 aggregation, namespaces, and advanced scope
Prem Kumar Badri
 
PPTX
Module 13 operators, delegates, and events
Prem Kumar Badri
 
PPTX
Module 11 : Inheritance
Prem Kumar Badri
 
PPTX
Module 10 : creating and destroying objects
Prem Kumar Badri
 
PPTX
Module 9 : using reference type variables
Prem Kumar Badri
 
PPTX
Module 7 : Arrays
Prem Kumar Badri
 
PPTX
Module 6 : Essentials of Object Oriented Programming
Prem Kumar Badri
 
PPTX
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
PPTX
Module 4 : methods & parameters
Prem Kumar Badri
 
PPTX
Module 3 : using value type variables
Prem Kumar Badri
 
PPTX
Module 2: Overview of c#
Prem Kumar Badri
 
PPTX
Module 1 : Overview of the Microsoft .NET Platform
Prem Kumar Badri
 
PPTX
C# Multi threading
Prem Kumar Badri
 
PPT
C# Method overloading
Prem Kumar Badri
 
PPTX
C# Inheritance
Prem Kumar Badri
 
PPTX
C# Global Assembly Cache
Prem Kumar Badri
 
PPTX
C# Filtering in generic collections
Prem Kumar Badri
 
PPTX
C# File IO Operations
Prem Kumar Badri
 
Module 15 attributes
Prem Kumar Badri
 
Module 14 properties and indexers
Prem Kumar Badri
 
Module 12 aggregation, namespaces, and advanced scope
Prem Kumar Badri
 
Module 13 operators, delegates, and events
Prem Kumar Badri
 
Module 11 : Inheritance
Prem Kumar Badri
 
Module 10 : creating and destroying objects
Prem Kumar Badri
 
Module 9 : using reference type variables
Prem Kumar Badri
 
Module 7 : Arrays
Prem Kumar Badri
 
Module 6 : Essentials of Object Oriented Programming
Prem Kumar Badri
 
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
Module 4 : methods & parameters
Prem Kumar Badri
 
Module 3 : using value type variables
Prem Kumar Badri
 
Module 2: Overview of c#
Prem Kumar Badri
 
Module 1 : Overview of the Microsoft .NET Platform
Prem Kumar Badri
 
C# Multi threading
Prem Kumar Badri
 
C# Method overloading
Prem Kumar Badri
 
C# Inheritance
Prem Kumar Badri
 
C# Global Assembly Cache
Prem Kumar Badri
 
C# Filtering in generic collections
Prem Kumar Badri
 
C# File IO Operations
Prem Kumar Badri
 
Ad

Recently uploaded (20)

PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
community health nursing question paper 2.pdf
Prince kumar
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Ad

Module 8 : Implementing collections and generics

  • 2. Overview  Examining Collections and Collection Interfaces  Working with Primary Collection Types  Working with Generic Collections  Working with Specialized Collections  Working with Collection Base Classes
  • 3. Lesson 1: Examining Collections and Collection Interfaces  What Are Collections?  What Are Generic Collections?  What Are Collection Interfaces?  Discussion: Identifying the Uses of Advanced and Generic Collections and Collection Interfaces
  • 4. Collections store arbitrary objects in a structured manner. Types of collections available within the .NET Framework are: What Are Collections? Arrays Advanced collections  Non-generic collections  Generic collections
  • 5. What Are Generic Collections? Generic collections support the storage of both value types and reference types. Only a single data type is allowed to be stored inside a generic collection. Following are the generic collection types: Generic Dictionary Generic List Generic Stack Generic Queue Generic LinkedList Generic Interface
  • 6. What Are Collection Interfaces? A collection interface allows a collection to support a different behavior. Collection interfaces are: IComparable ICollection IList IComparer IEqualityComparer IDictionary IEnumerable IEnumerator
  • 7. Lesson 2: Working with Primary Collection Types  How a Flexible Collection of Reference Types Is Created by Using ArrayList  How Circular Collections Are Managed by Using Stack and Queue Classes  How to Iterate Through the Elements of a Collection by Using Enumerators  How Reference Types Are Accessed Based on Key/Value Pairs and Comparers  How Boolean Values Are Stored in a BitArray by Using the BitArray Class  Discussion: Identifying the Uses of Non-Generic Collections
  • 8. How a Flexible Collection of Reference Types Is Created by Using ArrayList A class representing a list, which is similar to a single-dimensional array that you can resize dynamically ArrayList Dim countries As New ArrayList() countries.Add("Belgium") countries.Add("China") countries.Add("France") countries.Add("New Zealand") ArrayList countries = new ArrayList(); countries.Add("Belgium"); countries.Add ("China"); countries.Add("France"); countries.Add("New Zealand"); Visual Basic C#
  • 9. How Circular Collections Are Managed by Using Stack and Queue Classes A stack can be visualized as a stack of books arranged one on top of the other. You can pick or access the top- most book in the stack because it was the last book added. The Stack class works on the same principle Stack A queue can be visualized as a line in a grocery store, where customers enter the queue from the rear and exit the queue from the front. Therefore, the first customer to enter the queue is the first to exit it. The Queue class follows the same principle Queue
  • 10. How to Iterate Through the Elements of a Collection by Using Enumerators To support enumeration, you:  Implement the IEnumerable interface in Visual Basic  Use the yield statement in C# rather than implementing the IEnumerable interface
  • 11. How Reference Types Are Accessed Based on Key/Value Pairs and Comparers Comparer class compares two objects to detect if they are less than, greater than, or equal to one another Hashtable class represents a collection of name/value pairs, organized based on the hash code of the key being specified SortedList class represents a collection of name/value pairs, accessible either by key or by index, but sorted only by keys
  • 12. How Boolean Values Are Stored in a BitArray by Using the BitArray Class BitArray is a class in the .NET Framework that allows you to implement bit structures BitArray Class
  • 13. Lesson 3: Working with Generic Collections  How Type-Safe Collections Are Created by Using Generic List Types  How Type-Safe Collections Are Created by Using Generic Collections  How Reference Types Are Accessed Based on Type-Safe Key/Value Pairs  How Type-Safe Doubly Linked Lists Are Created by Using Generic Collections  Discussion: Identifying the Uses of Generic Collections
  • 14. How Type-Safe Collections Are Created by Using Generic List Types Generic List class: Provides methods to search, sort, and manipulate the elements of a generic list Creates a generic list that provides the behavior of an ArrayList
  • 15. How Type-Safe Collections Are Created by Using Generic Collections The generic Stack class represents a variable size LIFO collection of objects of same data typeGeneric Stack Class The generic Queue class represents a variable size FIFO collection of elements of same data type Generic Queue Class
  • 16. How Reference Types Are Accessed Based on Type-Safe Key/Value Pairs The .NET Framework provides the following classes in the System.Collections.Generic namespace that help you to add name and value pairs to a collection: Dictionary SortedList SortedDictionary
  • 17. How Type-Safe Doubly Linked Lists Are Created by Using Generic Collections Generic LinkedList class: Defines nodes that have a common data type, and each node points to the previous and following nodes Helps create and manage a strongly typed doubly linked list
  • 18. Lesson 4: Working with Specialized Collections  What are Specialized Collections?  How Type-Safe Strings Are Created by Using Specialized String Classes  How High-Performance Dictionaries Are Created by Using Specialized Collections  How Collections with String-Based Keys Are Created by Using Specialized Classes  How Data Is Stored Efficiently in Memory by Using Specialized Bit Structures  Practice: Evaluate When to Use a Specific Generic Collection
  • 19. What Are Specialized Collections? Specialized collections are predefined collections that serve a special or highly specific purpose. Specialized collection types are: String classes Dictionary classes NamedCollection classes Bit structures
  • 20. How Type-Safe Strings Are Created by Using Specialized String Classes Types of specialized string collections are: StringCollection StringDictionary StringEnumerator CollectionsUtil
  • 21. How High-Performance Dictionaries Are Created by Using Specialized Collections Types of specialized dictionary collections are: Is a simple implementation of the IDictionary interface by using a singly linked list ListDictionary Uses the appropriate implementation for a dictionary depending on the size of the collection HybridDictionary Represents a collection of key/value pairs that are ordered based on the key or the index OrderedDictionary
  • 22. How Collections with String-Based Keys Are Created by Using Specialized Classes Classes in the System.Collections.Specialized namespace allow you to create collections with string-based keys. These classes are: NameObjectCollectionBase NameObjectCollectionBase.KeysCollection NameValueCollection
  • 23. How Data Is Stored Efficiently in Memory by Using Specialized Bit Structures Bit structure stores Boolean values in binary series of 1s and 0s and always uses 32 bits of storage Two specialized bit structures are:  BitVector32  BitVector32.Section Console.WriteLine(bv.ToString & " = " & bv.Data) Dim b1 As Integer = BitVector32.CreateMask() Dim b2 As Integer = BitVector32.CreateMask(b1) bv(b1) = True bv(b2) = True Console.WriteLine(bv.ToString & " = " & bv.Data) Dim s1 As BitVector32.Section = BitVector32.CreateSection(6) Dim s2 As BitVector32.Section = BitVector32.CreateSection(3, s1) Visual Basic Code Example
  • 24. Lesson 5: Working with Collection Base Classes How Custom Collections Are Created by Using Collection Base Classes How Custom Dictionary Types Are Created by Using Dictionary Base Types Discussion: Identifying the Differences Between Custom Collections and Custom Dictionary Types
  • 25. How Custom Collections Are Created by Using Collection Base Classes Two dictionary base classes are: Represents an abstract class for a strongly typed collection CollectionBase Class Represents an abstract base class for a strongly typed non-generic collection ReadOnlyCollectionB ase Class
  • 26. Defines a dictionary key/value pair in a dictionary collection How Custom Dictionary Types Are Created by Using Dictionary Base Types Two collection base classes are: Provides the abstract base class for a strongly typed collection of key value/pairs DictionaryBase Class DictionaryEntry Structure
  • 27. Review This module described: Examining collections and collection interfaces Working with primary collection types Working with generic collections Working with specialized collections Working with collection base classes
  • 28. Review  Overview of Arrays  Creating Arrays  Using Arrays