FluxSharp Data Types
This document provides a complete reference for FluxSharp's type system, covering primitive types, complex types, and type-related concepts.
Primitive Types
Primitive types are the fundamental data types built into the language.
Numeric Types
Type | Description | Example |
|---|---|---|
| 64-bit signed integer. The default integer type. | |
| 64-bit unsigned integer. | |
| 128-bit signed integer for very large numbers. | |
| 128-bit unsigned integer. | |
| 8-bit unsigned integer. | |
| 32-bit single-precision floating-point number. Requires an suffix. | |
| 64-bit double-precision floating-point number. | |
Text Types
: A sequence of characters. Strings are immutable.string
``
flux
string message = "Hello, World!";
string multiline = "Line 1\nLine 2";
`
char
: A single 16-bit Unicode character.
`
flux
char initial = 'A';
char newline = '\n';
`
Boolean Type
bool
: Represents a truth value, either
true
or
false
.
`
flux
bool isActive = true;
bool isComplete = false;
`
Void Type
void
: Indicates that a method does not return a value.
`
flux
public void LogMessage(string message) {
print(message);
// No return statement
}
`
Complex Types
Arrays
Arrays are fixed-size collections of elements of the same type.
Declaration:
type[size]
`
flux
int[10] scores; // An array of 10 integers
string[5] names; // An array of 5 strings
`
Initialization and Access:
`
flux
scores[0] = 95;
int firstScore = scores[0];
`
Multi-dimensional Arrays:
`
flux
int[3][3] matrix; // A 3x3 matrix
matrix[0][0] = 1;
`
Array sizes can be computed at compile time. For example:
byte[1024 * 4] block;
Classes and Structs
class
: A reference type for defining complex objects. See CLASSES.md for details.
struct
: A value type for creating simple, lightweight data structures. See CLASSES.md for details.
Type System Concepts
Type Literals
Literals are fixed values in source code.
Integer Literals:
`
flux
int decimal = 42;
int hex = 0xFF; // Hexadecimal (prefix 0x)
int binary = 0b1010; // Binary (prefix 0b)
`
Floating-Point Literals:
`
flux
float single = 3.14f; // 'f' suffix for float
double dbl = 3.14159; // Default is double
double scientific = 1.5e-10; // Scientific notation
`
String and Char Literals:
`
flux
string greeting = "Hello";
char grade = 'A';
`
Type Conversion (Casting)
FluxSharp is a statically-typed language. Conversions between types must be explicit if there's a risk of data loss.
double d = 9.78;
// Explicit cast from double to int. The fractional part is lost.
int i = (int)d; // i will be 9
int x = 100;
// Implicit cast from int to double. No data loss.
double y = x; // y will be 100.0
Default Values
Variables declared without an initial value are assigned a default value.
Type
Default Value
Numeric types (
int
,
float
, etc.)
bool
false
string
and other reference types
null
Nullable Types
Reference types (like
string
and class instances) can hold a
null` value, indicating that they do not refer to an object.
string name = null;
if (name != null) {
print(name);
}
Attempting to access a member of a
null
reference will result in a runtime error. Always check for
null
before using a reference type if it could be uninitialized.
Next: Read VARIABLES.md