SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Tendances (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
 

En vedette

Collections and generic class
Collections and generic classCollections and generic class
Collections and generic classifis
 
Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...
Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...
Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...Akhil Mittal
 
C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3Md. Mahedee Hasan
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examplesagni_agbc
 
C# OOP Advanced Concepts
C# OOP Advanced ConceptsC# OOP Advanced Concepts
C# OOP Advanced Conceptsagni_agbc
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net frameworkArun Prasad
 

En vedette (12)

Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Collections and generic class
Collections and generic classCollections and generic class
Collections and generic class
 
Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...
Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...
Diving in OOP (Day 3): Polymorphism and Inheritance (Dynamic Binding/Run Time...
 
C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3
 
Introduction to TFS 2013
Introduction to TFS 2013Introduction to TFS 2013
Introduction to TFS 2013
 
C# oop
C#   oopC#   oop
C# oop
 
C#, OOP introduction and examples
C#, OOP introduction and examplesC#, OOP introduction and examples
C#, OOP introduction and examples
 
OOP Basics
OOP BasicsOOP Basics
OOP Basics
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
C# OOP Advanced Concepts
C# OOP Advanced ConceptsC# OOP Advanced Concepts
C# OOP Advanced Concepts
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 

Similaire à Generic Programming &amp; Collection

Similaire à 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
 

Dernier

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Dernier (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
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?
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

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