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 &amp; Collection

Similar to Generic Programming &amp; Collection (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

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Generic Programming &amp; Collection

  • 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); }