SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie Generic Programming &amp; Collection

Ähnlich wie 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
 

Kürzlich hochgeladen

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
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
 
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
 

Kürzlich hochgeladen (20)

Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
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
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
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
 
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
 

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