SlideShare a Scribd company logo
1 of 23
GENERIC programming & COLLECTION Adhatus Solichah A.
Course Structure Interfaces of the System.Collections Generic methods, class, base class, interface
System.Array The most primitive container construct Provides services, e.g. reversing, sorting, clearing, and enumerating Has fixed upper limit it does not automatically resize itself as we add or clear items
System.Collections  contain types in a more flexible container The System.Collections namespace defines a number of interfaces
Interfaces of System.Collections
System.Collections Interface Hierarchy
ICollection The most primitive interface of System.Collections ICollection extends IEnumerable Provide small set of member to determine: the number of items in the container, thethread safety of the container, the ability to copy the contents into a System.Array type. public interface ICollection : IEnumerable { int Count { get; } bool IsSynchronized { get; } object SyncRoot { get; } void CopyTo(Array array, int index); }
IDictionary public interface IDictionary : ICollection, IEnumerable { bool IsFixedSize { get; } bool IsReadOnly { get; } object this[object key] { get; set; } ICollection Keys { get; } ICollection Values { get; } void Add(object key, object value); void Clear(); bool Contains(object key); IDictionaryEnumerator GetEnumerator(); void Remove(object key); } collection that maintains a set of name/value pairs IDictionary interface defines a Keys and Values property as well as Add(), Remove(), and Contains() methods.
IDictionaryEnumerator IDictionaryEnumerator is simply a strongly typed  enumerator, given that it extends IEnumerator IDictionaryEnumeratorallows to enumerate over items in the dictionary viathe generalized Entry property Ability to traverse the name/value pairs using the Key/Value properties. (sorting) public interface IDictionaryEnumerator : IEnumerator { DictionaryEntry Entry { get; } object Key { get; } object Value { get; } }
IList provides the ability to insert, remove,and index items into (or out of) a container public interface IList : ICollection, IEnumerable { bool IsFixedSize { get; } bool IsReadOnly { get; } object this[ int index ] { get; set; } int Add(object value); void Clear(); bool Contains(object value); int IndexOf(object value); void Insert(int index, object value); void Remove(object value); void RemoveAt(int index); }
Classes of System.Collections
Working with the ArrayList Type making use of the AddRange() method to populate ArrayList Insert() allows to plug a new item into theArrayList at a specified index. (zero based index) the call to the ToArray() methodreturns an array of System.Object typesbased on the contents of the original ArrayList.
Working with the Queue Type Queues are containers that ensure items are accessed using a first-in, first-out manner
Working with the Stack Type represents a collection that maintains items using a last-in, first-out manner. Stack defines a member named Push() and Pop()
Boxing & Unboxing Boxing Value type  Ref type Implicit Unboxing Ref type  Value type Explicit // Make a short value type. short s = 25; // Box the value into an object reference. object objShort = s; // Unbox the reference back into a corresponding short. short anotherShort = (short)objShort;
Boxing & Unboxing A new object must be allocated on the managed heap. The value of the stack-based data must be transferred into that memory location. When unboxed, the value stored on the heap-based object must be transferred back to the stack. The now unused object on the heap will (eventually) be garbage collected.
System.Collections.Generic Contains numerous class and interface types that allow you to contain subitems in a variety of containers generic interfaces mimic the corresponding nongeneric types in the System.Collections
::Non-generic:: class Bucket{ public string items; } ::Generic:: class Bucket<T>{ public T item; public void Add(T value); public T GetItem(); }
Classes of System.Collections.Generic
Limitations of Custom Generic Collections Possible Constraints for Generic Type Parameters
Creating Generic Base Classes generic classes can be the base class to other classes // Assume you have created a custom // generic list class. public class MyList<T> { private List<T> listOfData = new List<T>(); } // Concrete types must specify the typeparameter when deriving from a // generic base class. public class MyStringList : MyList<string> {} //or public class MyStringList<T> : MyList<T> {}
Creating Generic Interfaces public interface IBinaryOperations<T> where T : struct { T Add(T arg1, T arg2); T Subtract(T arg1, T arg2); T Multiply(T arg1, T arg2); T Divide(T arg1, T arg2); }
Next....... Delegate, Events and Lambdas

More Related Content

What's hot

What's hot (19)

C# Collection classes
C# Collection classesC# Collection classes
C# Collection classes
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Collections in Java
Collections in JavaCollections in Java
Collections in Java
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Java Collection framework
Java Collection frameworkJava Collection framework
Java Collection framework
 
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)
 
07 java collection
07 java collection07 java collection
07 java collection
 
collection framework in java
collection framework in javacollection framework in java
collection framework in java
 
Java collection
Java collectionJava collection
Java collection
 
Java.util
Java.utilJava.util
Java.util
 
Collections in Java Notes
Collections in Java NotesCollections in Java Notes
Collections in Java Notes
 
Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video Tutorial
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 
Java collections
Java collectionsJava collections
Java collections
 
JAVA Collections frame work ppt
 JAVA Collections frame work ppt JAVA Collections frame work ppt
JAVA Collections frame work ppt
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 

Similar to GENERIC programming & COLLECTION interfaces

Similar to GENERIC programming & COLLECTION interfaces (20)

Collections generic
Collections genericCollections generic
Collections generic
 
collections
 collections collections
collections
 
Generics collections
Generics collectionsGenerics collections
Generics collections
 
Collections
CollectionsCollections
Collections
 
Collection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshanCollection framework (completenotes) zeeshan
Collection framework (completenotes) zeeshan
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
List in java
List in javaList in java
List in java
 
Lecture 24
Lecture 24Lecture 24
Lecture 24
 
collectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptxcollectionframework-141116005344-conversion-gate01.pptx
collectionframework-141116005344-conversion-gate01.pptx
 
Presentation1
Presentation1Presentation1
Presentation1
 
Collections
CollectionsCollections
Collections
 
Collections
CollectionsCollections
Collections
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
javacollections.pdf
javacollections.pdfjavacollections.pdf
javacollections.pdf
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
JavaCollections.ppt
JavaCollections.pptJavaCollections.ppt
JavaCollections.ppt
 
JavaCollections.ppt
JavaCollections.pptJavaCollections.ppt
JavaCollections.ppt
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
collections
collectionscollections
collections
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

GENERIC programming & COLLECTION interfaces

  • 1. GENERIC programming & COLLECTION Adhatus Solichah A.
  • 2. Course Structure Interfaces of the System.Collections Generic methods, class, base class, interface
  • 3. System.Array The most primitive container construct Provides services, e.g. reversing, sorting, clearing, and enumerating Has fixed upper limit it does not automatically resize itself as we add or clear items
  • 4. System.Collections contain types in a more flexible container The System.Collections namespace defines a number of interfaces
  • 7. ICollection The most primitive interface of System.Collections ICollection extends IEnumerable Provide small set of member to determine: the number of items in the container, thethread safety of the container, the ability to copy the contents into a System.Array type. public interface ICollection : IEnumerable { int Count { get; } bool IsSynchronized { get; } object SyncRoot { get; } void CopyTo(Array array, int index); }
  • 8. IDictionary public interface IDictionary : ICollection, IEnumerable { bool IsFixedSize { get; } bool IsReadOnly { get; } object this[object key] { get; set; } ICollection Keys { get; } ICollection Values { get; } void Add(object key, object value); void Clear(); bool Contains(object key); IDictionaryEnumerator GetEnumerator(); void Remove(object key); } collection that maintains a set of name/value pairs IDictionary interface defines a Keys and Values property as well as Add(), Remove(), and Contains() methods.
  • 9. IDictionaryEnumerator IDictionaryEnumerator is simply a strongly typed enumerator, given that it extends IEnumerator IDictionaryEnumeratorallows to enumerate over items in the dictionary viathe generalized Entry property Ability to traverse the name/value pairs using the Key/Value properties. (sorting) public interface IDictionaryEnumerator : IEnumerator { DictionaryEntry Entry { get; } object Key { get; } object Value { get; } }
  • 10. IList provides the ability to insert, remove,and index items into (or out of) a container public interface IList : ICollection, IEnumerable { bool IsFixedSize { get; } bool IsReadOnly { get; } object this[ int index ] { get; set; } int Add(object value); void Clear(); bool Contains(object value); int IndexOf(object value); void Insert(int index, object value); void Remove(object value); void RemoveAt(int index); }
  • 12. Working with the ArrayList Type making use of the AddRange() method to populate ArrayList Insert() allows to plug a new item into theArrayList at a specified index. (zero based index) the call to the ToArray() methodreturns an array of System.Object typesbased on the contents of the original ArrayList.
  • 13. Working with the Queue Type Queues are containers that ensure items are accessed using a first-in, first-out manner
  • 14. Working with the Stack Type represents a collection that maintains items using a last-in, first-out manner. Stack defines a member named Push() and Pop()
  • 15. Boxing & Unboxing Boxing Value type  Ref type Implicit Unboxing Ref type  Value type Explicit // Make a short value type. short s = 25; // Box the value into an object reference. object objShort = s; // Unbox the reference back into a corresponding short. short anotherShort = (short)objShort;
  • 16. Boxing & Unboxing A new object must be allocated on the managed heap. The value of the stack-based data must be transferred into that memory location. When unboxed, the value stored on the heap-based object must be transferred back to the stack. The now unused object on the heap will (eventually) be garbage collected.
  • 17. System.Collections.Generic Contains numerous class and interface types that allow you to contain subitems in a variety of containers generic interfaces mimic the corresponding nongeneric types in the System.Collections
  • 18. ::Non-generic:: class Bucket{ public string items; } ::Generic:: class Bucket<T>{ public T item; public void Add(T value); public T GetItem(); }
  • 20. Limitations of Custom Generic Collections Possible Constraints for Generic Type Parameters
  • 21. Creating Generic Base Classes generic classes can be the base class to other classes // Assume you have created a custom // generic list class. public class MyList<T> { private List<T> listOfData = new List<T>(); } // Concrete types must specify the typeparameter when deriving from a // generic base class. public class MyStringList : MyList<string> {} //or public class MyStringList<T> : MyList<T> {}
  • 22. Creating Generic Interfaces public interface IBinaryOperations<T> where T : struct { T Add(T arg1, T arg2); T Subtract(T arg1, T arg2); T Multiply(T arg1, T arg2); T Divide(T arg1, T arg2); }