SlideShare a Scribd company logo
NON-GENERICS COLLECTION
WHAT ARE COLLECTIONS?
• Collections store arbitrary objects in a
structured manner. Types of collections
available within the .NET Framework are:
• ARRAYS
• ADVANCED COLLECTIONS -
i) Non - Generics
ii) Generics
Comparing Arrays to Collections
• An array cannot resize itself when full
– A collection class, such as ArrayList, can resize
• An array is intended to store elements of one
type
– A collection is designed to store elements of different
types
• Elements of an array cannot have read-only
access
– A collection can have read-only access
• In general, arrays are faster but less flexible
– Collections are slightly slower but more flexible
Non – Generic Collections
• A part of .Net - Framework since version 1.0
• Defined in the System.Collections namespace.
• General purpose data structures that operate
on OBJECT REFERENCES.
• Collections that hold the elements of different
datatypes.
Boxing and UnBoxing
• Boxing - The process of converting a value type to
the type object. When the CLR boxes a value type
,it wraps the value inside a System.Object and
stores it on the heap . Boxing is implicit .
• UnBoxing – It extracts the value type from object
type. UnBoxing is explicit.
• Disadvantage- It degrades the system
performance.
How a Flexible Collection of Reference
Types Is Created by Using ArrayList ??
• ArrayList -
A class representing a list, which is similar to a single-
dimensional array that you can
resize dynamically.
C# code-*-**
ArrayList countries = new ArrayList();
countries.Add("Belgium");
countries.Add ("China");
countries.Add("New Zealand");
Class ArrayList-
•Provides dynamic resizing of the collection
through the class’s method
•Property Capacity
•Manipulate the capacity of the ArrayList
•When ArrayList needs to grow, it by default
doubles its Capacity
•Store references to objects
•All classes derive from class object
•Can contain objects of any type
•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
STACK
• Class Stack
– Contains methods Push and Pop to perform the basic stack
operations.
– Method Push
• Takes and inserts an object to the top of the Stack
• Grows to accommodate more objects
– When the number of items on the Stack (the Count
property) is equal to the capacity at the time of the Push
operation
• Can store only references to objects
– Value types are implicitly boxed before they are added
– Method Pop
• Removes and returns the object current on the top of the
Stack
– Method Peek
• Returns the value of the top stack element
• Does not remove the element from the Stack
– Note on methods Pop and Peek
• Throws InvalidOperationException if the Stack is empty
– Property Count
• Obtain the number of elements in Stack
10
1 // Fig. 27.6: StackTest.cs
2 // Demonstrating class Stack.
3 using System;
4 using System.Collections;
5
6 public class StackTest
7 {
8 public static void Main( string[] args )
9 {
10 Stack stack = new Stack(); // default Capacity of 10
11
12 // create objects to store in the stack
13 bool aBoolean = true;
14 char aCharacter = '$';
15 int anInteger = 34567;
16 string aString = "hello";
17
18 // use method Push to add items to (the top of) the stack
19 stack.Push( aBoolean );
20 PrintStack( stack );
21 stack.Push( aCharacter );
22 PrintStack( stack );
23 stack.Push( anInteger );
24 PrintStack( stack );
25 stack.Push( aString );
26 PrintStack( stack );
27
28 // check the top element of the stack
29 Console.WriteLine( "The top element of the stack is {0}n",
30 stack.Peek() );
Outline
StackTest.cs
(1 of 3)
Create a stack with the default
initial capacity of 10
elements
Add four elements to the
stack
Obtain the value of the top stack
element
HASHTABLE
• Class HashTable
– Hashing
• Convert the application key rapidly to an index and the
information could be store/retrieve at that location in
the array
• The data is stored in a data structure called a hash table
• Convert a key into an array subscript
– Literally scramble the bits
» Makes a “hash” of the number
Adding entries to hashtable and
display them
Using System;
Using System.Collections;
Class Program
{
Static void main()
{
Hashtable hashtable = new Hashtable();
hashtable[1]=“one”;
hashtable[2]=“two”;
hashtable[13]=“thirteen”;
foreach(DictionaryEntry entry in hashtable)
{
Console.Writeline(“{0},{1}”, entry.key , entry.value);
}
}
}
COLLOSION
– The load factor
• The ratio of the number of objects stored in the hash
table to the total number of cells of the hash table
• Affects the performance of hashing schemes
–The chance of collisions tends to increase as this
ratio gets higher
– A hash function
• Performs a calculation that determines where to place
data in the hash table
• Applied to the key in a key–value pair of objects
– Class Hashtable can accept any object as a key
• Class object defines method GetHashCode that all
objects inherit.
DISADVANTAGES OF NON-GENERIC
COLLECTION
• Problems with Non-Generic Collections
– Hashtable stores its keys and data as object
references
• Say we store only string keys and int values by
convention
– Inefficient!
– Cannot control what is being put into the
Hashtable
Continue..
• Due to this disadvantages, they do not have
the type safety , therefore we go for generic
collections.
THANK YOU..

More Related Content

What's hot

Java & advanced java
Java & advanced javaJava & advanced java
Java & advanced java
BASAVARAJ HUNSHAL
 
exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.ppt
Varshini62
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
sivasundari6
 
Java script ppt
Java script pptJava script ppt
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
Arnab Bhaumik
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
lalithambiga kamaraj
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
css.ppt
css.pptcss.ppt
css.ppt
bhasula
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
adamcookeuk
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
JavabynataraJ
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
Jeanie Arnoco
 
java Features
java Featuresjava Features
java Features
Jadavsejal
 
Matplotlib Review 2021
Matplotlib Review 2021Matplotlib Review 2021
Matplotlib Review 2021
Bhaskar J.Roy
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
MustafaIbrahimy
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
vishal choudhary
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
Akhil Kaushik
 
Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Android
technoguff
 

What's hot (20)

Java & advanced java
Java & advanced javaJava & advanced java
Java & advanced java
 
exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.ppt
 
WHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVAWHAT IS ABSTRACTION IN JAVA
WHAT IS ABSTRACTION IN JAVA
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Event handling
Event handlingEvent handling
Event handling
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
css.ppt
css.pptcss.ppt
css.ppt
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
 
java Features
java Featuresjava Features
java Features
 
Matplotlib Review 2021
Matplotlib Review 2021Matplotlib Review 2021
Matplotlib Review 2021
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Android
 

Similar to C# Non generics collection

Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
rangariprajwal4554
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
Dr.Shweta
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_FrameworkKrishna Sujeer
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
agorolabs
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
Collections Training
Collections TrainingCollections Training
Collections Training
Ramindu Deshapriya
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
Janki Shah
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
iqbalphy1
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
Muhazzab Chouhadry
 
Standard template library
Standard template libraryStandard template library
Standard template library
Sukriti Singh
 
Java OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 4) - CollectionJava OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 4) - Collection
OUM SAOKOSAL
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On Workshop
Arpit Poladia
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
Sangharsh agarwal
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
GauravPatil318
 
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppttutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
AbdisamedAdam
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
Yonas D. Ebren
 
notes.pdf
notes.pdfnotes.pdf
notes.pdf
ssuserd14cca
 
Java collections
Java collectionsJava collections
Java collectionsSujit Kumar
 

Similar to C# Non generics collection (20)

Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
Javasession7
Javasession7Javasession7
Javasession7
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
 
Java 103 intro to java data structures
Java 103   intro to java data structuresJava 103   intro to java data structures
Java 103 intro to java data structures
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Stack in Sata Structure
Stack in Sata StructureStack in Sata Structure
Stack in Sata Structure
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Java OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 4) - CollectionJava OOP Programming language (Part 4) - Collection
Java OOP Programming language (Part 4) - Collection
 
Java Hands-On Workshop
Java Hands-On WorkshopJava Hands-On Workshop
Java Hands-On Workshop
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppttutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
notes.pdf
notes.pdfnotes.pdf
notes.pdf
 
Java collections
Java collectionsJava collections
Java collections
 

More from Prem Kumar Badri

Module 15 attributes
Module 15 attributesModule 15 attributes
Module 15 attributes
Prem Kumar Badri
 
Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexers
Prem Kumar Badri
 
Module 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scopeModule 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scope
Prem Kumar Badri
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and events
Prem Kumar Badri
 
Module 11 : Inheritance
Module 11 : InheritanceModule 11 : Inheritance
Module 11 : Inheritance
Prem Kumar Badri
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
Prem Kumar Badri
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variables
Prem Kumar Badri
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and generics
Prem Kumar Badri
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
Prem Kumar Badri
 
Module 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented ProgrammingModule 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented Programming
Prem Kumar Badri
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
Prem Kumar Badri
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
Prem Kumar Badri
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
Prem Kumar Badri
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET Platform
Prem Kumar Badri
 
C# Multi threading
C# Multi threadingC# Multi threading
C# Multi threading
Prem Kumar Badri
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
Prem Kumar Badri
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
Prem Kumar Badri
 
C# Generic collections
C# Generic collectionsC# Generic collections
C# Generic collections
Prem Kumar Badri
 
C# Global Assembly Cache
C# Global Assembly CacheC# Global Assembly Cache
C# Global Assembly Cache
Prem Kumar Badri
 

More from Prem Kumar Badri (20)

Module 15 attributes
Module 15 attributesModule 15 attributes
Module 15 attributes
 
Module 14 properties and indexers
Module 14 properties and indexersModule 14 properties and indexers
Module 14 properties and indexers
 
Module 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scopeModule 12 aggregation, namespaces, and advanced scope
Module 12 aggregation, namespaces, and advanced scope
 
Module 13 operators, delegates, and events
Module 13 operators, delegates, and eventsModule 13 operators, delegates, and events
Module 13 operators, delegates, and events
 
Module 11 : Inheritance
Module 11 : InheritanceModule 11 : Inheritance
Module 11 : Inheritance
 
Module 10 : creating and destroying objects
Module 10 : creating and destroying objectsModule 10 : creating and destroying objects
Module 10 : creating and destroying objects
 
Module 9 : using reference type variables
Module 9 : using reference type variablesModule 9 : using reference type variables
Module 9 : using reference type variables
 
Module 8 : Implementing collections and generics
Module 8 : Implementing collections and genericsModule 8 : Implementing collections and generics
Module 8 : Implementing collections and generics
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
Module 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented ProgrammingModule 6 : Essentials of Object Oriented Programming
Module 6 : Essentials of Object Oriented Programming
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
 
Module 4 : methods & parameters
Module 4 : methods & parametersModule 4 : methods & parameters
Module 4 : methods & parameters
 
Module 3 : using value type variables
Module 3 : using value type variablesModule 3 : using value type variables
Module 3 : using value type variables
 
Module 2: Overview of c#
Module 2:  Overview of c#Module 2:  Overview of c#
Module 2: Overview of c#
 
Module 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET PlatformModule 1 : Overview of the Microsoft .NET Platform
Module 1 : Overview of the Microsoft .NET Platform
 
C# Multi threading
C# Multi threadingC# Multi threading
C# Multi threading
 
C# Method overloading
C# Method overloadingC# Method overloading
C# Method overloading
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
C# Generic collections
C# Generic collectionsC# Generic collections
C# Generic collections
 
C# Global Assembly Cache
C# Global Assembly CacheC# Global Assembly Cache
C# Global Assembly Cache
 

Recently uploaded

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 

Recently uploaded (20)

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 

C# Non generics collection

  • 2. WHAT ARE COLLECTIONS? • Collections store arbitrary objects in a structured manner. Types of collections available within the .NET Framework are: • ARRAYS • ADVANCED COLLECTIONS - i) Non - Generics ii) Generics
  • 3. Comparing Arrays to Collections • An array cannot resize itself when full – A collection class, such as ArrayList, can resize • An array is intended to store elements of one type – A collection is designed to store elements of different types • Elements of an array cannot have read-only access – A collection can have read-only access • In general, arrays are faster but less flexible – Collections are slightly slower but more flexible
  • 4. Non – Generic Collections • A part of .Net - Framework since version 1.0 • Defined in the System.Collections namespace. • General purpose data structures that operate on OBJECT REFERENCES. • Collections that hold the elements of different datatypes.
  • 5. Boxing and UnBoxing • Boxing - The process of converting a value type to the type object. When the CLR boxes a value type ,it wraps the value inside a System.Object and stores it on the heap . Boxing is implicit . • UnBoxing – It extracts the value type from object type. UnBoxing is explicit. • Disadvantage- It degrades the system performance.
  • 6. How a Flexible Collection of Reference Types Is Created by Using ArrayList ?? • ArrayList - A class representing a list, which is similar to a single- dimensional array that you can resize dynamically. C# code-*-** ArrayList countries = new ArrayList(); countries.Add("Belgium"); countries.Add ("China"); countries.Add("New Zealand");
  • 7. Class ArrayList- •Provides dynamic resizing of the collection through the class’s method •Property Capacity •Manipulate the capacity of the ArrayList •When ArrayList needs to grow, it by default doubles its Capacity •Store references to objects •All classes derive from class object •Can contain objects of any type
  • 8. •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
  • 9. STACK • Class Stack – Contains methods Push and Pop to perform the basic stack operations. – Method Push • Takes and inserts an object to the top of the Stack • Grows to accommodate more objects – When the number of items on the Stack (the Count property) is equal to the capacity at the time of the Push operation • Can store only references to objects – Value types are implicitly boxed before they are added – Method Pop • Removes and returns the object current on the top of the Stack – Method Peek • Returns the value of the top stack element • Does not remove the element from the Stack – Note on methods Pop and Peek • Throws InvalidOperationException if the Stack is empty – Property Count • Obtain the number of elements in Stack
  • 10. 10 1 // Fig. 27.6: StackTest.cs 2 // Demonstrating class Stack. 3 using System; 4 using System.Collections; 5 6 public class StackTest 7 { 8 public static void Main( string[] args ) 9 { 10 Stack stack = new Stack(); // default Capacity of 10 11 12 // create objects to store in the stack 13 bool aBoolean = true; 14 char aCharacter = '$'; 15 int anInteger = 34567; 16 string aString = "hello"; 17 18 // use method Push to add items to (the top of) the stack 19 stack.Push( aBoolean ); 20 PrintStack( stack ); 21 stack.Push( aCharacter ); 22 PrintStack( stack ); 23 stack.Push( anInteger ); 24 PrintStack( stack ); 25 stack.Push( aString ); 26 PrintStack( stack ); 27 28 // check the top element of the stack 29 Console.WriteLine( "The top element of the stack is {0}n", 30 stack.Peek() ); Outline StackTest.cs (1 of 3) Create a stack with the default initial capacity of 10 elements Add four elements to the stack Obtain the value of the top stack element
  • 11. HASHTABLE • Class HashTable – Hashing • Convert the application key rapidly to an index and the information could be store/retrieve at that location in the array • The data is stored in a data structure called a hash table • Convert a key into an array subscript – Literally scramble the bits » Makes a “hash” of the number
  • 12. Adding entries to hashtable and display them Using System; Using System.Collections; Class Program { Static void main() { Hashtable hashtable = new Hashtable(); hashtable[1]=“one”; hashtable[2]=“two”; hashtable[13]=“thirteen”; foreach(DictionaryEntry entry in hashtable) { Console.Writeline(“{0},{1}”, entry.key , entry.value); } } }
  • 13. COLLOSION – The load factor • The ratio of the number of objects stored in the hash table to the total number of cells of the hash table • Affects the performance of hashing schemes –The chance of collisions tends to increase as this ratio gets higher – A hash function • Performs a calculation that determines where to place data in the hash table • Applied to the key in a key–value pair of objects – Class Hashtable can accept any object as a key • Class object defines method GetHashCode that all objects inherit.
  • 14. DISADVANTAGES OF NON-GENERIC COLLECTION • Problems with Non-Generic Collections – Hashtable stores its keys and data as object references • Say we store only string keys and int values by convention – Inefficient! – Cannot control what is being put into the Hashtable
  • 15. Continue.. • Due to this disadvantages, they do not have the type safety , therefore we go for generic collections.