Skip to content

Primitive types

SyntaxDescription
sbyte byte short ushort int uint long ulongInteger types
float a = 1.5f; double b = 2.5;float and double
decimal a = 1.5m;decimal
char c = 'a'; bool b = true;Characters and booleans
object o = "a"; string s = "b";object and string
SyntaxDescriptionErrorReasonInstead
System.IntPtr p = System.IntPtr.Zero;A raw pointer-width integerTUKI0102, TUKI0099runtimeUse int or long
Some types aren’t available because the runtime doesn’t have them (TUKI0102). The language itself doesn’t forbid them.

All 8 integer types are available. Integers narrower than int are promoted to int before an operation (Expressions).

using UnityEngine;
using Tsukimi;
public class TyPrimInts : TsukimiBehaviour
{
void Start()
{
sbyte a = 1; byte b = 2; short c = 3; ushort d = 4;
int e = 5; uint f = 6; long g = 7; ulong h = 8;
Debug.Log(a + b + c + d + e + (int)f + (int)g + (int)h); // => 36
}
}
using UnityEngine;
using Tsukimi;
public class TyPrimFloat : TsukimiBehaviour
{
void Start()
{
float a = 1.5f;
double b = 2.5;
Debug.Log(a + (float)b); // => 4
}
}

You can write a decimal literal and convert it to double.

using UnityEngine;
using Tsukimi;
public class TyPrimDecimal : TsukimiBehaviour
{
void Start()
{
decimal a = 1.5m;
Debug.Log((double)a); // => 1.5
}
}

char and bool are also carried by value.

using UnityEngine;
using Tsukimi;
public class TyPrimCharBool : TsukimiBehaviour
{
void Start()
{
char c = 'a';
bool b = true;
int code = c;
Debug.Log(code); // => 97
Debug.Log(b); // => true
}
}

object and string are carried by reference.

using UnityEngine;
using Tsukimi;
public class TyPrimObjStr : TsukimiBehaviour
{
void Start()
{
object o = "a";
string s = "b";
Debug.Log(o.ToString() + s); // => "ab"
}
}