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:
-
charin Rust andCharin .NET have different definitions. In Rust, acharis 4 bytes wide that is a Unicode scalar value, but in .NET, aCharis 2 bytes wide and stores the character using the UTF-16 encoding. For more information, see the Rustchardocumentation. -
While a unit
()(an empty tuple) in Rust is an expressible value, the closest cousin in C# would bevoidto represent nothing. However,voidisn't an expressible value except when using pointers and unsafe code. .NET hasValueTuplethat is an empty tuple, but C# does not have a literal syntax like()to represent it.ValueTuplecan be used in C#, but it's very uncommon. Unlike C#, F# does have a unit type like Rust. -
While
voidandobjectare not scalar types (even though scalars likeintare sub-classes ofobjectin the .NET type hierarchy), they have been included in the above table for convenience.
See also: