Nullable<T>
Nullable<int>
int
public TResult Result() { if (_result is null) throw new Exception("Given result type is an error"); return (TResult) _result; }
int?
public class ParseResult<TResult, TError>{ private readonly TResult? _result; private readonly TError? _error; private ParseResult(TResult? result, TError? error) { _result = result; _error = error; } public bool IsError() => _error is not null; public TResult Result() { if (_result is null) throw new Exception("Given result type is an error"); return (TResult) _result; } public static ParseResult<TResult, TError> CreatedResult(TResult result) => new(result, default); public static ParseResult<TResult, TError> CreateError(TError error) => new(default, error);}
.Value