User Tools

Site Tools


generics

Differences

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

Link to this comparison view

Next revision
Previous revision
generics [2018/02/10 09:02] – created wolfgangriedmanngenerics [2018/08/20 04:06] (current) wolfgangriedmann
Line 1: Line 1:
 ====== Generics ====== ====== Generics ======
  
-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.+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 visualfoxpro>local oList as List<string>
  
 oList := List<string>{} oList := List<string>{}
Line 9: Line 11:
 oList:Add( "hi guys" )</code> oList:Add( "hi guys" )</code>
 The List class is defined as follows: The List class is defined as follows:
-<code></code>+<code visualfoxpro>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. 
 + 
 +===== 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]]
  
 Please see these two topics of the Microsoft C# Programming Guide: Please see these two topics of the Microsoft C# Programming Guide:
   * [[https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-classes|Generic Classes]]   * [[https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-classes|Generic Classes]]
   * [[https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-type-parameters|Generic Type Parameters]]   * [[https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-type-parameters|Generic Type Parameters]]
 +
 +Another source of more information about generics can be found in the Pearls section of the X# forums: [[https://www.xsharp.info/forum/pearls/247-getting-to-grips-with-generics|Getting to grips with generics]]
  
 Please note that Vulcan.NET could use methods with generic type parameters, but could not let you create them. Please note that Vulcan.NET could use methods with generic type parameters, but could not let you create them.
  
generics.1518253355.txt.gz · Last modified: 2018/02/10 09:02 by wolfgangriedmann