The string encodes to slightly different values with the standard and URL base64 encoders (trailing + vs -) but they both decode to the original string as desired.
In C#, we use the Convert class for Base64 encoding and decoding. The ToBase64String method is used for encoding, while FromBase64String is used for decoding. For URL-safe encoding, we manually replace the characters ‘+’ and ‘/’ with ‘-’ and ‘_’ respectively.
Unlike the Go example, C# doesn’t have a built-in URL-safe Base64 encoder, so we implement it manually by replacing characters after encoding. When decoding, we reverse this process before calling FromBase64String.
Error handling in C# is typically done using try-catch blocks, which is demonstrated in the decoding part of the example.