Function Call Expression

Summary

Calls a function with the specified arguments.

Syntax

function([ argument1 [, argument2 [, ... argumentN ] ] ])

Parameters

function
The name of the function to call.
argumentN
Any legal expression to supply as an argument to the function.

Description

A function call expression is used to execute a specified function with the provided arguments.

If the function being called is overloaded, the compiler will attempt to match the argument types with the function parameter types. If there are no matching function declarations, a compile-time error will be raised. If there is more than one possible match, the compiler will use the most specific overload first before attempting to convert argument types. See the function overloading page for more information on overloading is handled.

Examples

Basic Usage
1
2
3
4
5
6
7
8
9
import System;
 
int plus(int a, int b) {
    return a + b;
}
 
Console.log(plus(1, 1)); // 2
Console.log(plus(1, 3)); // 4
Console.log(plus(5, 5)); // 10
Calling Overloaded Functions
1
2
3
4
5
6
7
8
9
10
11
12
13
import System;
 
// First overload
int plus(int a, int b) {
    return a + b;
}
// Second overload
int plus(int a, int b, int c) {
    return a + b + c;
}
 
Console.log(plus(1, 1));    // Calls first overload. Result: 2
Console.log(plus(1, 1, 1)); // Calls second overload. Result: 3

See Also

Share

HTML | BBCode | Direct Link