ソースコード
public static class NullableExt { public static void Deconstruct<T> ( this T? self, out bool hasValue, out T value ) where T : struct { hasValue = self.HasValue; value = self ?? default; } }
使用例
var now = DateTime.Now; var ( hasValue, value ) = new DateTime?( now );
参考ツイート
Here's an extension method for you leveraging C# 7.1. Deconstruct any nullable into a tuple! #csharp @dotnet pic.twitter.com/yPNR8XYlbW
— 🅳🅰🆅🅸🅳 🅿🅸🅽🅴 (@davidpine7) December 15, 2017