User Tools

Site Tools


generics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
generics [2018/02/10 11:48] wolfgangriedmanngenerics [2018/02/10 14:59] wolfgangriedmann
Line 2: Line 2:
  
 Generics are a new feature in the .NET framework, and they permit to specify also the type of a parameter for a function. Whenever you see a ''<T>'' parameter, it is a generic definition (but it could be any letter). Generics are a new feature in the .NET framework, and they permit to specify also the type of a parameter for a function. Whenever you see a ''<T>'' parameter, it is a generic definition (but it could be any letter).
 +===== Use of generics =====
 +
 As sample how to use generics look at the [[collections:list|System.Collections.Generic.List<T>]] class: As sample how to use generics look at the [[collections:list|System.Collections.Generic.List<T>]] class:
 <code>local oList as List<string> <code>local oList as List<string>
Line 11: Line 13:
 <code>public class List<T> implements IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T></code> <code>public class List<T> implements IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T></code>
 That means that you need to define which datatype the List object should contain. In the sample before it is a string, but it can be any datatype/class. That means that you need to define which datatype the List object should contain. In the sample before it is a string, but it can be any datatype/class.
 +
 +===== Define a method with generics =====
 +
 +===== Define a class with generics =====
 +
 +===== More informations =====
 +
 You can also look at this page for a better explanation: [[http://www.tutorialsteacher.com/csharp/csharp-generics|http://www.tutorialsteacher.com/csharp/csharp-generics]] You can also look at this page for a better explanation: [[http://www.tutorialsteacher.com/csharp/csharp-generics|http://www.tutorialsteacher.com/csharp/csharp-generics]]
  
generics.txt · Last modified: 2018/08/20 04:06 by wolfgangriedmann