@example

Summary

Provides example usage for the item being documented.

Syntax

@example title
code

Parameters

title
The title of the example.
code
Example code showing example usage of the item being documented.

Description

The @example tag is used for documenting example usage(s) of the item being documented.

For instance, if a method is being documented, the @example tag can document how the method can be called or illustrate scenarios the method can be useful.

The title of the example must occur on the same line as the @example tag. Code should always begin on the next line following the @example tag.

Examples

Documenting an 'add' Method
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Calculator
{
    /**
     * Adds two numbers together and returns the result.
     *
     * @example Basic Usage
     * add(1, 1); // 2
     * add(2, 2); // 4
     * add(2, 3); // 5
     */
    int add(int x, int y)
    {
        return x + y;
    }
}
Multiple @example Tags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Calculator
{
    /**
     * Adds two numbers together and returns the result.
     *
     * @example 1 + 1
     * add(1, 1); // 2
     *
     * @example 2 + 2
     * add(2, 2); // 4
     *
     * @example 2 + 3
     * add(2, 3); // 5
     */
    int add(int x, int y)
    {
        return x + y;
    }
}

Share

HTML | BBCode | Direct Link