Access modifiers
public and private define which functions and struct members may be accessed from other scopes.
Default visibility
Namespace-level functions and struct members are private by default. Writing private makes that default explicit; writing public exposes the declaration outside its owning namespace or struct.
namespace Library;
int CalculateCore() { return 40; } // private by default
private int InternalValue() { return 2; } // explicitly private
public int Calculate() { return CalculateCore() + InternalValue(); }
Code in another namespace may call Library.Calculate(). Private functions remain available to other declarations inside Library.
Struct members
The same modifiers apply to fields, methods, constructors, destructors, properties, indexers and static members. Private members are accessible from code belonging to the declaring struct; public members form its external API.
struct Counter
{
private int value;
public Counter(int initialValue)
{
value = initialValue;
}
public int Value
{
get { return value; }
}
private void ResetCore()
{
value = 0;
}
}
Positional brace construction follows the same visibility rules. Code outside Counter cannot write value through Counter { ... }; it must call the public constructor or another public factory supplied by the type.
Visibility and native linkage
public controls visibility inside Xenon source code. export additionally makes a function public and exposes it as a native symbol, while extern declares a native function implemented elsewhere.
public int Add(int a, int b) { return a + b; }
export int NativeAdd(int a, int b) { return a + b; }