Functions are categorized into two types based on their declaration and how they interact with struct's.
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
structinstance. 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 0Static 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);