User Tools

Site Tools


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 (but it could be any letter).

Use of generics

As sample how to use generics look at the System.Collections.Generic.List<T> class:

local oList as List<string>
 
oList := List<string>{}
oList:Add( "hi girls" )
oList:Add( "hi guys" )

The List class is defined as follows:

public class List<T> implements IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>

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

Please see these two topics of the Microsoft C# Programming Guide:

Another source of more information about generics can be found in the Pearls section of the X# forums: Getting to grips with generics

Please note that Vulcan.NET could use methods with generic type parameters, but could not let you create them.

generics.txt · Last modified: 2018/08/20 06:06 by wolfgangriedmann