Skip to main content

Generic Methods

Methods can accept type parameters for type-safe operations on any type.


Syntax

Swap method<T>(a as T, b as T) {
temp is another a;
a is b;
b is temp;
}

Calling

The compiler infers the type parameter:

x is 10;
y is 20;
Swap(x, y);
Print(x); // 20
Print(y); // 10

With Return Type

Identity method<T>(value as T) as T {
return value;
}

result is Identity(42); // int
name is Identity("hello"); // string

Next Steps