Created
June 6, 2021 14:29
-
-
Save rstropek/d090ecba8dac70006f184377ff1a89a3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#nullable enable | |
using System; | |
Err err; | |
// Note that we can now mix declaration and tuple deconstruction | |
(var ret1, err) = GetAnswer(); | |
if (err == null) Console.WriteLine(ret1); | |
// Go-like error handling anybody? | |
(var ret2, err) = GetAnswer_Error(); | |
if (err != null) Console.WriteLine(err); | |
(int?, Err?) GetAnswer() => (42, null); | |
(int?, Err?) GetAnswer_Error() => (null, new()); | |
class Err { public string Message => "Error"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment