Skip to content

String.Empty returns Some #1186

Answered by CK-LinoPro
tjidde-nl asked this question in Q&A
Discussion options

You must be logged in to vote

null and string.Empty are two distinctly different values.
Optional((string)null) will return None, while Optional(string.Empty) will return Some(string.Empty).
This is completely intentional since you might want to handle both cases separately.

If you want to filter for empty strings, you can do something like this:

string? someString;
var optionalString = Optional(someString).Filter(s => s != string.Empty);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@louthy
Comment options

Answer selected by tjidde-nl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants