SlideShare a Scribd company logo
1 of 20
COLLECTIONS IN .NET
Contents
• Introduction to collection
• Useful collection classes
1. ArrayList
2. Hashtable
3. Stack
4. Queue
5. BitArray
6. SortedList
Introduction
Collection means a group of different types of
data.
It provides automatic memory management and
capacity expansion.
The System.Collections namespace provides
various classes such as ArrayList, Stack,
Queue, Hashtable, SortedList and BitArray.
Some collections classes provides search and
sort capabilities on the basis of index values or
associated key values of the elements.
1. ArrayList
• It represents ordered collection of an object that
can be indexed individually.
• It is an alternative of an array. Unlike array, you
can
– Add or remove items from a specified position using
an index.
– Array resizes itself automatically.
• It also allows dynamic memory allocation, adding,
searching and sorting items in the list.
1. ArrayList
• Properties of ArrayList:
Property Description
Capacity Gets or sets the number of elements that the ArrayList
can contain.
Count Gets the number of elements actually contained in the
ArrayList.
IsFixedSize Gets a value indicating whether the ArrayList has a fixed size.
IsReadOnly Gets a value indicating whether the ArrayList is read only.
Item Gets or sets the element at the specified index.
Example:
using system;
using system.collections;
namespace CollectionApp
{ class Program
{ static void Main(string[] args)
{
ArrayList a1=new ArrayList();
a1.add(104);
a1.add(101);
a1.add(103);
Console.WriteLine(“Capacity:”,a1.Capacity);
Console.WriteLine(“Count:”,a1.Count);
foreach ( int i in a1) { Console.Write(i+” “); }
Console.WriteLine(“Sorted Contens”);
a1.Sort();
foreach ( int i in a1) { Console.Write(i+” “); }
Console.ReadLine();
}
}
}
2. Hashtable
• It is used when you need to access elements by using
key.
• Each item in the Hashtable has key/value pair. This
key is used to access the items in the collection.
2. Hashtable
• Properties of Hashtable:
Property Description
Count Gets no. of key/value pair contained in the table.
IsFixedSize Gets a value indicating whether the Hashtable has a fixed size.
IsReadOnly Gets a value indicating whether the Hashtable is read only.
Item
Gets or sets the value associated with the specified key.
Keys
Gets an ICollection containing the keys in the Hashtable.
Values Gets an ICollection containing the values in the Hashtable.
Example:
using system;
using system.collections;
namespace CollectionApp
{ class Program
{ static void Main(string[] args)
{
Hashtable ht=new Hashtable();
ht.add(“111”,”AAA”);
ht.add(“222”,”BBB”);
ht.add(“333”,”CCC”);
if(ht.ContainsValue(“DDD”))
{ Console.WriteLine(“Already is in table”); }
else
{ ht.Add(“444”,”DDD”); }
ICollection key = ht.Keys;
foreach ( string k in key) { Console.Write(k+”:”+ht[k]); }
Console.ReadLine();
}
}
}
3. SortedList
• A SortedList is a combination of ArrayList and
hashtable.
• It uses a key as well as an index to access the items
in a list.
• The collection of items is always sorted by the key
value.
3. SortedList
• Properties of SortedList:
Property Description
Capacity Gets or sets the capacity of Sortedlist
Count Gets the no. of elements contained in the SortedList.
IsFixedSize Gets a value indicating whether the SortedList has a fixed size.
IsReadOnly Gets a value indicating whether the SortedList is read only.
Item
Gets or sets the value associated with the specified key in
SortedList.
Keys
Gets the keys in the SortedList.
Values Gets the values in the SortedList.
Example:
using system;
using system.collections;
namespace CollectionApp
{ class Program
{ static void Main(string[] args)
{
SortedList sl=new SortedList();
sl.add(“111”,”AAA”);
sl.add(“222”,”BBB”);
sl.add(“333”,”CCC”);
if(sl.ContainsValue(“DDD”))
{ Console.WriteLine(“Already is in table”); }
else
{ sl.Add(“444”,”DDD”); }
ICollection key = sl.Keys;
foreach ( string k in key) { Console.Write(k+”:”+sl[k]); }
Console.ReadLine();
}
}
}
4. Stack
• It represents last-in, first-out collection of object.
• It is used when you need a last-in, first-out access of
items.
• Operations on Stack:
1. Push() : Adding an item to the stack.
2. Pop() : Removing an item from stack.
• Properties of Stack:
Example:
using system;
using system.collections;
namespace CollectionApp
{ class Program
{ static void Main(string[] args)
{
Stack st = new Stack();
st.Push(‘A’);
st.Push(‘M’);
st.Push(‘G’);
st.Push(‘W’);
Console.WriteLine(“Current Stack:”);
foreach( char c in st ) { Console.Write( c + “ “); }
Console.WriteLine(“Removing items”);
st.Pop();
st.Pop();
Console.WriteLine(“Current Stack:”);
foreach( char c in st ) { Console.Write( c + “ “); }
}
} }
5. Queue
• It represents first-in, first-out collection of object.
• It is used when you need a first-in, first-out access of
items.
• Operations on Queue:
1. Enqueue : Adding an item to queue.
2. Dequeue : Removing an item from queue.
• Properties of Queue:
Example:
using system;
using system.collections;
namespace CollectionApp
{ class Program
{ static void Main(string[] args)
{
Queue q = new Queue();
q.Enqueue(‘A’);
q.Enqueue(‘M’);
q.Enqueue(‘G’);
q.Enqueue(‘W’);
Console.WriteLine(“Current Queue:”);
foreach( char c in q ) { Console.Write( c + “ “); }
Console.WriteLine(“Removing items”);
char ch = (char)q.Dequeue();
Console.WriteLine(“Removed”,ch);
char ch = (char)q.Dequeue();
Console.WriteLine(“Removed”,ch);
Console.WriteLine(“Current Queue:”);
foreach( char c in q) { Console.Write(c+ “ “); } }}}
6. BitArray
• It represents an array of binary representation using
the values 0’s and 1’s.
• It is used when you need to store the bits but you don’t
know the no. of bits in advance.
• You can access items from BitArray collection by
using an integer index, which starts from 0.
6. BitArray
• Properties of BitArray:
Property Description
Count Gets the no. of elements contained in the BitArray.
IsReadOnly Gets a value indicating whether the BitArray is read only.
Item
Gets or sets the value of the bit at a specific position in
BitArray.
Length Gets or sets the number of elements in the BitArray.
Example:
using system;
using system.collections;
namespace CollectionApp
{ class Program
{ static void Main(string[] args)
{
BitArray b = new BitArray(8);
byte [] a = { 11 };
b = new BitArray(a);
Console.WriteLine(“BitArray b for a=11:”);
for( int i=0; i<b.Count; i++)
{
Console.WriteLine(b[i]);
}
}
}
}
Collections in .net technology (2160711)

More Related Content

What's hot (20)

Lecture11 standard template-library
Lecture11 standard template-libraryLecture11 standard template-library
Lecture11 standard template-library
 
Arrays
ArraysArrays
Arrays
 
Collections generic
Collections genericCollections generic
Collections generic
 
Array list
Array listArray list
Array list
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
LectureNotes-03-DSA
LectureNotes-03-DSALectureNotes-03-DSA
LectureNotes-03-DSA
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Data structures in c#
Data structures in c#Data structures in c#
Data structures in c#
 
Arrays
ArraysArrays
Arrays
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
2 introduction to data structure
2  introduction to data structure2  introduction to data structure
2 introduction to data structure
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
Array ppt
Array pptArray ppt
Array ppt
 
2 b queues
2 b queues2 b queues
2 b queues
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
8 python data structure-1
8 python data structure-18 python data structure-1
8 python data structure-1
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 

Similar to Collections in .net technology (2160711)

Similar to Collections in .net technology (2160711) (20)

Collection
CollectionCollection
Collection
 
12_-_Collections_Framework
12_-_Collections_Framework12_-_Collections_Framework
12_-_Collections_Framework
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
C# Non generics collection
C# Non generics collectionC# Non generics collection
C# Non generics collection
 
Presentation1
Presentation1Presentation1
Presentation1
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Collections - Lists & sets
Collections - Lists & setsCollections - Lists & sets
Collections - Lists & sets
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
collections
 collections collections
collections
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
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
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
Java Collections Tutorials
Java Collections TutorialsJava Collections Tutorials
Java Collections Tutorials
 
Javasession7
Javasession7Javasession7
Javasession7
 
Java Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptxJava Programming Comprehensive Guide.pptx
Java Programming Comprehensive Guide.pptx
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
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
 
Collections lecture 35 40
Collections lecture 35 40Collections lecture 35 40
Collections lecture 35 40
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 

More from Janki Shah

Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical MethodsGauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical MethodsJanki Shah
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
Addressing in Computer Networks
Addressing in Computer NetworksAddressing in Computer Networks
Addressing in Computer NetworksJanki Shah
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management SystemJanki Shah
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital ElectronicsJanki Shah
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Janki Shah
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Janki Shah
 
Sorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmSorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmJanki Shah
 

More from Janki Shah (9)

Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical MethodsGauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
Gauss Elimination & Gauss Jordan Methods in Numerical & Statistical Methods
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Addressing in Computer Networks
Addressing in Computer NetworksAddressing in Computer Networks
Addressing in Computer Networks
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Number system in Digital Electronics
Number system in Digital ElectronicsNumber system in Digital Electronics
Number system in Digital Electronics
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...Compiler in System Programming/Code Optimization techniques in System Program...
Compiler in System Programming/Code Optimization techniques in System Program...
 
Sorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of AlgorithmSorting in Linear Time in Analysis & Design of Algorithm
Sorting in Linear Time in Analysis & Design of Algorithm
 

Recently uploaded

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 

Recently uploaded (20)

VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 

Collections in .net technology (2160711)

  • 2. Contents • Introduction to collection • Useful collection classes 1. ArrayList 2. Hashtable 3. Stack 4. Queue 5. BitArray 6. SortedList
  • 3. Introduction Collection means a group of different types of data. It provides automatic memory management and capacity expansion. The System.Collections namespace provides various classes such as ArrayList, Stack, Queue, Hashtable, SortedList and BitArray. Some collections classes provides search and sort capabilities on the basis of index values or associated key values of the elements.
  • 4. 1. ArrayList • It represents ordered collection of an object that can be indexed individually. • It is an alternative of an array. Unlike array, you can – Add or remove items from a specified position using an index. – Array resizes itself automatically. • It also allows dynamic memory allocation, adding, searching and sorting items in the list.
  • 5. 1. ArrayList • Properties of ArrayList: Property Description Capacity Gets or sets the number of elements that the ArrayList can contain. Count Gets the number of elements actually contained in the ArrayList. IsFixedSize Gets a value indicating whether the ArrayList has a fixed size. IsReadOnly Gets a value indicating whether the ArrayList is read only. Item Gets or sets the element at the specified index.
  • 6. Example: using system; using system.collections; namespace CollectionApp { class Program { static void Main(string[] args) { ArrayList a1=new ArrayList(); a1.add(104); a1.add(101); a1.add(103); Console.WriteLine(“Capacity:”,a1.Capacity); Console.WriteLine(“Count:”,a1.Count); foreach ( int i in a1) { Console.Write(i+” “); } Console.WriteLine(“Sorted Contens”); a1.Sort(); foreach ( int i in a1) { Console.Write(i+” “); } Console.ReadLine(); } } }
  • 7. 2. Hashtable • It is used when you need to access elements by using key. • Each item in the Hashtable has key/value pair. This key is used to access the items in the collection.
  • 8. 2. Hashtable • Properties of Hashtable: Property Description Count Gets no. of key/value pair contained in the table. IsFixedSize Gets a value indicating whether the Hashtable has a fixed size. IsReadOnly Gets a value indicating whether the Hashtable is read only. Item Gets or sets the value associated with the specified key. Keys Gets an ICollection containing the keys in the Hashtable. Values Gets an ICollection containing the values in the Hashtable.
  • 9. Example: using system; using system.collections; namespace CollectionApp { class Program { static void Main(string[] args) { Hashtable ht=new Hashtable(); ht.add(“111”,”AAA”); ht.add(“222”,”BBB”); ht.add(“333”,”CCC”); if(ht.ContainsValue(“DDD”)) { Console.WriteLine(“Already is in table”); } else { ht.Add(“444”,”DDD”); } ICollection key = ht.Keys; foreach ( string k in key) { Console.Write(k+”:”+ht[k]); } Console.ReadLine(); } } }
  • 10. 3. SortedList • A SortedList is a combination of ArrayList and hashtable. • It uses a key as well as an index to access the items in a list. • The collection of items is always sorted by the key value.
  • 11. 3. SortedList • Properties of SortedList: Property Description Capacity Gets or sets the capacity of Sortedlist Count Gets the no. of elements contained in the SortedList. IsFixedSize Gets a value indicating whether the SortedList has a fixed size. IsReadOnly Gets a value indicating whether the SortedList is read only. Item Gets or sets the value associated with the specified key in SortedList. Keys Gets the keys in the SortedList. Values Gets the values in the SortedList.
  • 12. Example: using system; using system.collections; namespace CollectionApp { class Program { static void Main(string[] args) { SortedList sl=new SortedList(); sl.add(“111”,”AAA”); sl.add(“222”,”BBB”); sl.add(“333”,”CCC”); if(sl.ContainsValue(“DDD”)) { Console.WriteLine(“Already is in table”); } else { sl.Add(“444”,”DDD”); } ICollection key = sl.Keys; foreach ( string k in key) { Console.Write(k+”:”+sl[k]); } Console.ReadLine(); } } }
  • 13. 4. Stack • It represents last-in, first-out collection of object. • It is used when you need a last-in, first-out access of items. • Operations on Stack: 1. Push() : Adding an item to the stack. 2. Pop() : Removing an item from stack. • Properties of Stack:
  • 14. Example: using system; using system.collections; namespace CollectionApp { class Program { static void Main(string[] args) { Stack st = new Stack(); st.Push(‘A’); st.Push(‘M’); st.Push(‘G’); st.Push(‘W’); Console.WriteLine(“Current Stack:”); foreach( char c in st ) { Console.Write( c + “ “); } Console.WriteLine(“Removing items”); st.Pop(); st.Pop(); Console.WriteLine(“Current Stack:”); foreach( char c in st ) { Console.Write( c + “ “); } } } }
  • 15. 5. Queue • It represents first-in, first-out collection of object. • It is used when you need a first-in, first-out access of items. • Operations on Queue: 1. Enqueue : Adding an item to queue. 2. Dequeue : Removing an item from queue. • Properties of Queue:
  • 16. Example: using system; using system.collections; namespace CollectionApp { class Program { static void Main(string[] args) { Queue q = new Queue(); q.Enqueue(‘A’); q.Enqueue(‘M’); q.Enqueue(‘G’); q.Enqueue(‘W’); Console.WriteLine(“Current Queue:”); foreach( char c in q ) { Console.Write( c + “ “); } Console.WriteLine(“Removing items”); char ch = (char)q.Dequeue(); Console.WriteLine(“Removed”,ch); char ch = (char)q.Dequeue(); Console.WriteLine(“Removed”,ch); Console.WriteLine(“Current Queue:”); foreach( char c in q) { Console.Write(c+ “ “); } }}}
  • 17. 6. BitArray • It represents an array of binary representation using the values 0’s and 1’s. • It is used when you need to store the bits but you don’t know the no. of bits in advance. • You can access items from BitArray collection by using an integer index, which starts from 0.
  • 18. 6. BitArray • Properties of BitArray: Property Description Count Gets the no. of elements contained in the BitArray. IsReadOnly Gets a value indicating whether the BitArray is read only. Item Gets or sets the value of the bit at a specific position in BitArray. Length Gets or sets the number of elements in the BitArray.
  • 19. Example: using system; using system.collections; namespace CollectionApp { class Program { static void Main(string[] args) { BitArray b = new BitArray(8); byte [] a = { 11 }; b = new BitArray(a); Console.WriteLine(“BitArray b for a=11:”); for( int i=0; i<b.Count; i++) { Console.WriteLine(b[i]); } } } }