# Functions

## Defining a Function

Here is a C# function compared to the Linx version:

![A process diagram](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-060a5644d808a4a2aaf6e6de134d9dcb821155f3%2Fprocesses1.png?alt=media)

1. The Function definition lives in the Solution Explorer.
2. Its **Parameters** property defines the input parameters.
3. Its **Result** property defines the output results.
4. The central working area contains the body of the function.
5. Linx does not have an explicit ‘return’. When the Function finishes, the Result set is returned.

***

## Setting the Result of a Function

1. Use the **Return** function, which comes from the Linx Plugin.
2. The **Value** property of the Return function must be set to what the function's result value should be. Select a relevant in-scope item from the dropdown list, enter a literal value in the property field, or use the Expression Editor in the dropdown to build the expression. The ‘=\` in front of the value indicates that the value is an expression and not a literal value.

![Using Return](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-916204ca4767a0fc55226d2dd0e7fcc5cbb3640d%2Fprocesses2.png?alt=media)

Click **DEBUG** to run the Function and see the result.

***

## Calling a Function

Calling a Function is similar to one function calling another in programming.

![Process parameters](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-546db4b88b3f8603e17fc0a068be96916d1805ff%2Fprocesses3.png?alt=media)

1. Functions are dragged onto the body of another Function to call them.
2. Parameters of the called Function are visible as Properties.

Click **DEBUG** to run the Function and see the result.

***

## Using the Result of a Function

The body of a Function works exactly like the body of a programming function. Statements and expressions are added in a top-down fashion and can refer to items in its scope. When we add another **AddNumbers** Function to the body of **UseAddNumbers**, we can set its parameters to the result of the first **AddNumbers**:

![Using results](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-48d2f63cbff24a4a122eabc2e3f674e8949aa2ac%2Fprocesses4.png?alt=media)

To set the value of any of the sub-functions' results or calculations to the main function's result, add a **Return** function at the end of the execution sequence:

![Return function at end of sequence](https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-9c9961cd63253a24a54cd2fcddb19c82a8c6bb5e%2Fprocesses5.png?alt=media)

Click **DEBUG** to run the Function and see the result.
