Scalar Types
The following table lists the primitive types in Rust and their equivalent in C# and .NET:
Rust | C# | .NET | Note |
---|---|---|---|
bool | bool | Boolean | |
char | char | Char | See note 1. |
i8 | sbyte | SByte | |
i16 | short | Int16 | |
i32 | int | Int32 | |
i64 | long | Int64 | |
i128 | Int128 | ||
isize | nint | IntPtr | |
u8 | byte | Byte | |
u16 | ushort | UInt16 | |
u32 | uint | UInt32 | |
u64 | ulong | UInt64 | |
u128 | UInt128 | ||
usize | nuint | UIntPtr | |
f32 | float | Single | |
f64 | double | Double | |
decimal | Decimal | ||
() | void | Void or ValueTuple | See notes 2 & 3. |
object | Object | See note 3. |
Notes:
-
char
in Rust andChar
in .NET have different definitions. In Rust, achar
is 4 bytes wide that is a Unicode scalar value, but in .NET, aChar
is 2 bytes wide and stores the character using the UTF-16 encoding. For more information, see the Rustchar
documentation. -
While a unit
()
(an empty tuple) in Rust is an expressible value, the closest cousin in C# would bevoid
to represent nothing. However,void
isn't an expressible value except when using pointers and unsafe code. .NET hasValueTuple
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. -
While
void
andobject
are not scalar types (even though scalars likeint
are sub-classes ofobject
in the .NET type hierarchy), they have been included in the above table for convenience.
See also: