Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 974 Bytes

File metadata and controls

49 lines (35 loc) · 974 Bytes

Functions

Functions are categorized into two types based on their declaration and how they interact with struct's.

Instance Functions

Instance function operate on the struct instance by reference.

Instance functions are the default for any function declared inside a struct without the static modifier.

Instance functions are strictly used to access or modify the struct instance. They cannot trigger a destructor.

struct Vector
{
    public int X;
    public int Y;

    public void Reset()
    {
        X = 0;
        Y = 0;
    }
}

var v = new Vector(10, 10);

v.Reset();
// 'v.X' is 0
// 'v.Y' is 0

Static Functions

Static functions are declared inside a struct using the static modifier.

They do not operate on a specific instance and are accessed via the struct's type name.

struct MathUtils
{
    public static int Add(int a, int b)
    {
        return a + b;
    }
}

int sum = MathUtils.Add(10, 20);