Scalar Types

The following table lists the primitive types in Rust and their equivalent in C# and .NET:

RustC#.NETNote
boolboolBoolean
charcharCharSee note 1.
i8sbyteSByte
i16shortInt16
i32intInt32
i64longInt64
i128Int128
isizenintIntPtr
u8byteByte
u16ushortUInt16
u32uintUInt32
u64ulongUInt64
u128UInt128
usizenuintUIntPtr
f32floatSingle
f64doubleDouble
decimalDecimal
()voidVoid or ValueTupleSee notes 2 & 3.
objectObjectSee note 3.

Notes:

  1. char in Rust and Char in .NET have different definitions. In Rust, a char is 4 bytes wide that is a Unicode scalar value, but in .NET, a Char is 2 bytes wide and stores the character using the UTF-16 encoding. For more information, see the Rust char documentation.

  2. While a unit () (an empty tuple) in Rust is an expressible value, the closest cousin in C# would be void to represent nothing. However, void isn't an expressible value except when using pointers and unsafe code. .NET has ValueTuple that is an empty tuple, but C# does not have a literal syntax like () to represent it. ValueTuple can be used in C#, but it's very uncommon. Unlike C#, F# does have a unit type like Rust.

  3. While void and object are not scalar types (even though scalars like int are sub-classes of object in the .NET type hierarchy), they have been included in the above table for convenience.

See also: