Skip to content

Instantly share code, notes, and snippets.

@rstropek
Created June 6, 2021 14:29
Show Gist options
  • Save rstropek/d090ecba8dac70006f184377ff1a89a3 to your computer and use it in GitHub Desktop.
Save rstropek/d090ecba8dac70006f184377ff1a89a3 to your computer and use it in GitHub Desktop.
#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