Primitive types
Forms that compile (5)
Section titled “Forms that compile (5)”| Syntax | Description |
|---|---|
sbyte byte short ushort int uint long ulong | Integer 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 |
Forms that don’t compile (1)
Section titled “Forms that don’t compile (1)”| Syntax | Description | Error | Reason | Instead |
|---|---|---|---|---|
System.IntPtr p = System.IntPtr.Zero; | A raw pointer-width integer | TUKI0102, TUKI0099 | runtime | Use int or long |
Some types aren’t available because the runtime doesn’t have them (TUKI0102). The language itself doesn’t forbid them. |
Integers
Section titled “Integers”Integer types
Section titled “Integer types”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 }}Fractional numbers
Section titled “Fractional numbers”float and double
Section titled “float and double”using UnityEngine;using Tsukimi;
public class TyPrimFloat : TsukimiBehaviour{ void Start() { float a = 1.5f; double b = 2.5; Debug.Log(a + (float)b); // => 4 }}decimal
Section titled “decimal”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 }}Characters and booleans
Section titled “Characters and booleans”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
Section titled “object and string”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" }}