Created
October 17, 2022 01:40
-
-
Save ufcpp/33438c5c12dbe7a00b9dfb5f582673b4 to your computer and use it in GitHub Desktop.
ParseOrNull
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.WriteLine("123".ParseOrNull<int>()); | |
Console.WriteLine("1a3".ParseOrNull<int>()); | |
static class Ex | |
{ | |
public static T? ParseOrNull<T>(this string? s, IFormatProvider? provider = null) | |
where T : struct, IParsable<T> | |
=> T.TryParse(s, provider, out var value) ? value : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment