4 ms·
C# can be much better, or it can be much the same. It depends on which implementation you use. Standardisation is an issue here, the system library has the "Nul
by SideburnsOfDoom 4y ago
C# can be much better, or it can be much the same. It depends on which implementation you use. Standardisation is an issue here, the system library has the "Nullable<T>" struct (1), but not a standard Result<T, E> class (or struct). Popular libraries such as "OneOf" use a class type. The single-valued "OneOf" type is effectively an "Option<T>" (2)
Nullable<T> itself is not exactly the same as Option<T> since it does not cover types that already allow nulls. It adds nulls rather then removing them.
Many people roll their own Option<T> or Result<T,E> type, since it's easy enough to start, and it's usually a class type.
1) https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 https://learn.microsoft.com/en-us/dotnet/api/system.nullable...
2) https://github.com/mcintyre321/OneOf/blob/master/OneOf/OneOfBaseT0.generated.cs https://github.com/mcintyre321/OneOf/blob/master/OneOf/OneOf...